@eum-agent/agent-management 0.0.0-stage → 1.0.1
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/index.js +823 -0
- package/package.json +45 -3
- package/ui/ui.js +2985 -0
- package/README.md +0 -3
package/ui/ui.js
ADDED
|
@@ -0,0 +1,2985 @@
|
|
|
1
|
+
import { Alert, AlertDialog, Avatar, Button, DataTable, Dialog, DialogContent, DialogHeader, DialogTitle, EmptyState, Failure, Field, FormFailure, Input, InputNumber, PLUGIN_ICONS, Panel, ReadFailure, RenderingRegion, Segmented, Select, SlotOutlet, Switch, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Tooltip, TooltipContent, TooltipHint, TooltipTrigger, Warning, agentDeleted, agentOf, cn, codePoints, contributionsIn, failureText, goToSession, i18next, localeLeaves, pictureOf, pngDataUrl, resolveLabel, useAgents, useAvatarPicker, useBrowserService, useGateway, useGatewayAction, useGatewayRead, useNavigation, usePlugins, useToast, useTranslation, uuid } from "@eum-agent/host/framework";
|
|
2
|
+
import { createContext, createElement, forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region ui-src/styles.css?raw
|
|
5
|
+
var styles_default = "@layer components {\n [data-slot=\"settings-panel\"] {\n container-type: inline-size;\n }\n}\n\n.ag-shell {\n display: grid;\n flex: 1;\n min-height: 0;\n grid-template-columns: 15rem minmax(0, 1fr);\n}\n.ag-list {\n display: flex;\n flex-direction: column;\n min-height: 0;\n padding: 0 0.75rem 0.75rem;\n border-inline-end: 1px solid var(--border);\n}\n.ag-list-title {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.5rem;\n flex: none;\n height: 4rem;\n padding-inline: 0.625rem 0;\n}\n.ag-list-title h2 {\n font-size: 1.125rem;\n font-weight: 600;\n}\n.ag-list-title [data-slot=\"button\"],\n.ag-list-title [data-slot=\"tooltip-trigger\"] {\n color: var(--muted-foreground);\n}\n.ag-rows {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n overflow-y: auto;\n}\n.ag-group {\n display: flex;\n flex-direction: column;\n gap: 2px;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n.ag-group-title {\n margin: 1rem 0 0.25rem;\n padding-inline: 0.625rem;\n font-size: 0.75rem;\n color: var(--muted-foreground);\n}\n.ag-row {\n --row-fill: var(--card);\n position: relative;\n min-width: 0;\n border-radius: var(--radius-control);\n background: var(--row-fill);\n transition: background-color 150ms ease;\n}\n.ag-row:hover {\n --row-fill: var(--muted);\n}\n.ag-row[data-active] {\n --row-fill: var(--accent);\n}\n.ag .ag-row-open {\n display: flex;\n align-items: center;\n gap: 0.75rem;\n width: 100%;\n min-width: 0;\n padding: 0.625rem;\n border-radius: var(--radius-control);\n text-align: start;\n cursor: pointer;\n}\n.ag .ag-row-open:focus-visible {\n outline: none;\n}\n.ag-row:has(> .ag-row-open:focus-visible) {\n outline: var(--focus-ring-width) solid var(--focus-ring-color);\n}\n.ag-row-name {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-width: 0;\n}\n.ag-row-name strong,\n.ag-row-name small {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.ag-row-name strong {\n font-size: 0.875rem;\n font-weight: 500;\n}\n.ag-row[data-active] .ag-row-name strong {\n color: var(--accent-foreground);\n}\n.ag-row-name small {\n margin-top: 0.125rem;\n font-size: 0.75rem;\n color: var(--muted-foreground);\n}\n.ag-chapter-icon {\n display: grid;\n flex: none;\n place-items: center;\n width: 2rem;\n height: 2rem;\n border-radius: var(--radius-pill);\n background: var(--muted);\n color: var(--muted-foreground);\n}\n.ag-row:is(:hover, [data-active]) .ag-chapter-icon {\n background: var(--card);\n}\n/* Hover actions fade into the row, as the model and MCP lists do. */\n.ag-row-actions {\n position: absolute;\n inset-block: 0;\n inset-inline-end: 0;\n display: flex;\n align-items: center;\n gap: 0.125rem;\n padding-inline: 1.25rem 0.375rem;\n border-radius: var(--radius-control);\n background: linear-gradient(to right, transparent, var(--row-fill) 1rem);\n opacity: 0;\n pointer-events: none;\n transition: opacity 150ms ease;\n}\n.ag-row:hover .ag-row-actions,\n.ag-row:focus-within .ag-row-actions {\n opacity: 1;\n pointer-events: auto;\n}\n@media (hover: none) {\n .ag-row-actions {\n opacity: 1;\n pointer-events: auto;\n }\n}\n.ag-list-foot {\n flex: none;\n padding-top: 0.75rem;\n}\n.ag-detail {\n display: flex;\n flex-direction: column;\n min-width: 0;\n min-height: 0;\n}\n.ag-detail-header {\n display: flex;\n align-items: center;\n gap: 0.875rem;\n flex: none;\n min-height: 4.5rem;\n padding: 1rem 3.5rem 0.75rem 1.5rem;\n}\n.ag-grow {\n flex: 1;\n min-width: 0;\n}\n.ag-detail-header h3 {\n overflow: hidden;\n font-size: 1.125rem;\n font-weight: 600;\n line-height: 1.4;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.ag-detail-header small {\n display: block;\n font-size: 0.75rem;\n color: var(--muted-foreground);\n}\n.ag-tabs {\n display: flex;\n flex: 1;\n flex-direction: column;\n min-height: 0;\n min-width: 0;\n gap: 0;\n}\n.ag-tabs > .ag-tabs-list {\n flex: none;\n margin-inline: 1.5rem;\n}\n.ag-tab {\n min-height: 0;\n overflow-y: auto;\n padding: 1rem 1.5rem 0.25rem;\n}\n.ag-tab.ag-tab-skills:not([hidden]) {\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n.ag-tab.ag-tab-fill {\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n.ag-chapter-body {\n flex: 1;\n min-height: 0;\n overflow-y: auto;\n padding: 0 1.5rem 1.5rem;\n}\n/* One label column with the model and MCP forms. */\n@container (min-width: 28rem) {\n .ag-detail .settings-field-row {\n grid-template-columns: 7rem minmax(0, 1fr);\n }\n}\n/* Discard and save, one equal share each, at the foot of the column. */\n/* The footer's buttons rest 0.75rem above the pane's floor, where the list\n * column's add button rests, so the two bottom rows line up. */\n.ag-footer {\n display: flex;\n flex: none;\n flex-direction: column;\n gap: 0.75rem;\n padding: 0.5rem 1.5rem 0.75rem;\n}\n.ag-footer-actions {\n display: flex;\n gap: 0.5rem;\n}\n.ag-footer-actions > * {\n flex: 1 1 0;\n min-width: 0;\n}\n@container ag (max-width: 38rem) {\n .ag-shell {\n grid-template-columns: minmax(0, 1fr);\n grid-template-rows: auto minmax(0, 1fr);\n }\n .ag-list {\n flex-direction: row;\n align-items: center;\n gap: 0.5rem;\n padding: 0.5rem 3rem 0.5rem 1rem;\n border-inline-end: 0;\n border-bottom: 1px solid var(--border);\n }\n .ag-list-title h2,\n .ag-row-name small,\n .ag-group-title {\n display: none;\n }\n .ag-list-title {\n order: 2;\n height: auto;\n padding: 0;\n }\n .ag-rows {\n flex-direction: row;\n gap: 2px;\n overflow-x: auto;\n overflow-y: hidden;\n }\n .ag-group {\n flex-direction: row;\n }\n .ag-row {\n flex: none;\n }\n .ag .ag-row-open {\n padding: 0.375rem 0.625rem 0.375rem 0.375rem;\n gap: 0.5rem;\n }\n /* The chosen chip keeps its actions inline: a strip has no hover room. */\n .ag-row[data-active] {\n display: flex;\n align-items: center;\n padding-inline-end: 0.25rem;\n }\n .ag-row .ag-row-actions {\n display: none;\n }\n .ag-row[data-active] .ag-row-actions {\n position: static;\n display: flex;\n padding: 0;\n background: none;\n opacity: 1;\n pointer-events: auto;\n }\n .ag-list-foot {\n order: 3;\n padding: 0;\n }\n .ag-list-foot [data-slot=\"button\"] {\n width: auto;\n }\n .ag-detail-header,\n .ag-tab,\n .ag-chapter-body,\n .ag-footer {\n padding-inline: 1rem;\n }\n .ag-tabs > .ag-tabs-list {\n margin-inline: 1rem;\n }\n}\n";
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region ui-src/locales/en-US.ts
|
|
8
|
+
/** Text owned by this browser capability. */
|
|
9
|
+
var catalogue$1 = {
|
|
10
|
+
runSettings: {
|
|
11
|
+
blocked: "Configuration recovery is incomplete. New rounds are blocked until reading succeeds.",
|
|
12
|
+
current: "Current limits: {{steps}} steps per round; token budget {{budget}}.",
|
|
13
|
+
unlimited: "unlimited",
|
|
14
|
+
unconfirmed: "Save outcome is unconfirmed; current limits were reread and your draft was kept.",
|
|
15
|
+
unconfirmedFailed: "Save outcome is unconfirmed; your draft was kept. Retry reading the current limits.",
|
|
16
|
+
changed: "Limits changed elsewhere; your draft has been kept.",
|
|
17
|
+
title: "Runtime settings",
|
|
18
|
+
execution: "Execution limits",
|
|
19
|
+
maxSteps: "Steps per round",
|
|
20
|
+
budgetEnabled: "Limit token budget",
|
|
21
|
+
tokenBudget: "Cumulative token budget",
|
|
22
|
+
timing: "Applies to rounds started after saving; the current round keeps its limits.",
|
|
23
|
+
saved: "Execution limits saved",
|
|
24
|
+
positive: "Enter a positive whole number."
|
|
25
|
+
},
|
|
26
|
+
revisions: {
|
|
27
|
+
title: "Versions",
|
|
28
|
+
back: "Back to configuration",
|
|
29
|
+
refresh: "Refresh",
|
|
30
|
+
memory: "Versions are kept for this runtime only",
|
|
31
|
+
saved: "This restore saved v{{revision}}. Current version: v{{current}}. Configuration takes effect at its usual time.",
|
|
32
|
+
before: "Before",
|
|
33
|
+
after: "After",
|
|
34
|
+
loading: "Loading…",
|
|
35
|
+
confirm: "Restore v{{to}} over v{{from}} and save a new version",
|
|
36
|
+
unchanged: "Configuration is unchanged",
|
|
37
|
+
restore: "Restore this version",
|
|
38
|
+
cancel: "Cancel",
|
|
39
|
+
human: "User",
|
|
40
|
+
agent: "Agent",
|
|
41
|
+
system: "Initial configuration",
|
|
42
|
+
current: "Current",
|
|
43
|
+
compare: "Compare version",
|
|
44
|
+
sourceMissing: "Source session is unavailable",
|
|
45
|
+
source: "Open source session",
|
|
46
|
+
more: "Load earlier versions",
|
|
47
|
+
noDifference: "These versions have no differences",
|
|
48
|
+
timing: "Prompts and tools apply on the next model request. The default model applies to new sessions. MCP connections follow the existing connection rules.",
|
|
49
|
+
fields: {
|
|
50
|
+
name: "Name",
|
|
51
|
+
description: "Description",
|
|
52
|
+
avatar: "Avatar",
|
|
53
|
+
startsSessions: "Starts sessions",
|
|
54
|
+
tools: "Tools",
|
|
55
|
+
prompts: {
|
|
56
|
+
identity: "Identity",
|
|
57
|
+
instructions: "Instructions",
|
|
58
|
+
style: "Style",
|
|
59
|
+
reminder: "Reminder"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
agents: {
|
|
64
|
+
external: "External agents",
|
|
65
|
+
add: "Add agent",
|
|
66
|
+
identifier: "Identifier",
|
|
67
|
+
emptyHint: "Add agents with their own default model.",
|
|
68
|
+
heading: "Agents",
|
|
69
|
+
hint: "A session belongs to one agent, and the agent decides which tools it is offered.",
|
|
70
|
+
name: "Name",
|
|
71
|
+
namePlaceholder: "Name this agent",
|
|
72
|
+
tools: "Tools",
|
|
73
|
+
toolsHint: "Sessions under this agent are offered these tools.",
|
|
74
|
+
toolsEmpty: "This agent is offered no tools at all.",
|
|
75
|
+
none: "No agents yet",
|
|
76
|
+
tabs: {
|
|
77
|
+
basic: "Basics",
|
|
78
|
+
prompts: "Prompts",
|
|
79
|
+
tools: "Tools"
|
|
80
|
+
},
|
|
81
|
+
unsaved: "Unsaved",
|
|
82
|
+
dirty: "Unsaved changes",
|
|
83
|
+
discard: "Discard changes",
|
|
84
|
+
leaveTitle: "Discard unsaved changes?",
|
|
85
|
+
leaveBody: "These pages have changes that are not saved:",
|
|
86
|
+
leaveStay: "Keep editing",
|
|
87
|
+
changedElsewhere: "Changed elsewhere",
|
|
88
|
+
loadRemote: "Load new value",
|
|
89
|
+
description: "Description",
|
|
90
|
+
descriptionPlaceholder: "What this agent does, in one sentence",
|
|
91
|
+
nameRequired: "A name is required",
|
|
92
|
+
descriptionTooLong: "The description cannot be longer than {{limit}} characters",
|
|
93
|
+
startsSessions: "Available for chat",
|
|
94
|
+
remove: "Delete",
|
|
95
|
+
removeHint: "Delete agent",
|
|
96
|
+
removeTitle: "Delete agent “{{name}}”?",
|
|
97
|
+
removeBody: "Its sessions are kept and stay readable, but cannot be continued. Its directory agents/{{id}}/ (AGENTS.md and its own skills) is deleted, together with its version history, picture, model settings and file access grants. This cannot be undone.",
|
|
98
|
+
deleted: "Deleted agent",
|
|
99
|
+
startsSessionsAlways: "The general-purpose agent is always available for chat.",
|
|
100
|
+
directChatOn: "Available for chat: it can be picked for a new session. Click to turn off",
|
|
101
|
+
directChatOff: "Not available for chat: delegation only. Click to turn on",
|
|
102
|
+
avatar: "Avatar",
|
|
103
|
+
prompts: {
|
|
104
|
+
slots: "Prompt slots",
|
|
105
|
+
identity: "Identity",
|
|
106
|
+
instructions: "Behavior",
|
|
107
|
+
style: "Style",
|
|
108
|
+
reminder: "Reminder",
|
|
109
|
+
about: "About {{slot}}",
|
|
110
|
+
purpose: "Purpose",
|
|
111
|
+
placement: "Where it goes",
|
|
112
|
+
example: "For example: {{text}}",
|
|
113
|
+
info: {
|
|
114
|
+
identity: {
|
|
115
|
+
purpose: "Who this agent is: its role, persona and voice.",
|
|
116
|
+
example: "You are a careful code reviewer who speaks plainly and leads with the verdict.",
|
|
117
|
+
where: "The Identity chapter of the system prompt, right after the opening “You are <name>”, inside an <identity> tag.",
|
|
118
|
+
scope: "Root sessions and sessions delegated to this agent both carry it.",
|
|
119
|
+
cache: "Editing it invalidates the prompt cache prefix of existing sessions; their next step writes the cache again.",
|
|
120
|
+
tip: "It describes a role and never relaxes the built-in safety and permission rules."
|
|
121
|
+
},
|
|
122
|
+
style: {
|
|
123
|
+
purpose: "How this agent writes its replies: tone, length and format.",
|
|
124
|
+
example: "Keep answers to three paragraphs at most and show only the changed code.",
|
|
125
|
+
where: "The Tone and output chapter of the system prompt, inside a <style> tag, taking precedence over that chapter’s built-in points.",
|
|
126
|
+
scope: "Root sessions and sessions delegated to this agent both carry it.",
|
|
127
|
+
cache: "Editing it invalidates the prompt cache prefix of existing sessions; their next step writes the cache again.",
|
|
128
|
+
tip: "It governs how things are said and never relaxes the built-in safety and permission rules."
|
|
129
|
+
},
|
|
130
|
+
reminder: {
|
|
131
|
+
purpose: "One or two rules that must not be forgotten on any step.",
|
|
132
|
+
example: "Always run the tests before committing.",
|
|
133
|
+
where: "Outside the system prompt: appended after the whole conversation on every step, inside a <reminder> tag that opens with “Standing reminder from the person who set you up:”.",
|
|
134
|
+
scope: "Root sessions only; sessions delegated to this agent leave it out.",
|
|
135
|
+
cache: "Editing it leaves the prompt cache intact.",
|
|
136
|
+
tip: "Keep it short; the limit is {{limit}} characters."
|
|
137
|
+
},
|
|
138
|
+
instructions: {
|
|
139
|
+
purpose: "This agent’s working rules, on top of the built-in working posture; where the two conflict, these win.",
|
|
140
|
+
example: "Ask me before changing the database schema.",
|
|
141
|
+
where: "Kept as the file {{path}} and injected into the <instructions> block of the system prompt’s Working posture chapter.",
|
|
142
|
+
scope: "Root sessions and sessions delegated to this agent both carry it.",
|
|
143
|
+
cache: "Editing it invalidates the prompt cache prefix of existing sessions; their next step writes the cache again.",
|
|
144
|
+
tip: "In a root session the agent can edit this file itself when you ask; the change applies from its next step."
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
readFailed: "The rules file cannot be read and cannot be edited: {{reason}}"
|
|
148
|
+
},
|
|
149
|
+
toolSettings: {
|
|
150
|
+
tool: "Tool",
|
|
151
|
+
permitted: "Allow calls",
|
|
152
|
+
forbidden: "Block calls",
|
|
153
|
+
preload: "Preload",
|
|
154
|
+
preloadOn: "Preloaded. Click to load on demand.",
|
|
155
|
+
preloadOff: "Loaded on demand. Click to preload.",
|
|
156
|
+
deferred: "On demand",
|
|
157
|
+
cancelPreload: "Stop preloading",
|
|
158
|
+
defaultSuggestion: "Suggested default",
|
|
159
|
+
followDefault: "Following default",
|
|
160
|
+
customized: "Customized",
|
|
161
|
+
restoreDefault: "Restore default",
|
|
162
|
+
resetDefaultsHint: "Reset access and preload settings for every tool, including tools hidden by search",
|
|
163
|
+
on: "On",
|
|
164
|
+
off: "Off",
|
|
165
|
+
preloadInactive: "Calls are blocked; this preference is inactive.",
|
|
166
|
+
preloadUnavailable: "Preload configuration is unavailable. Saved preferences are retained.",
|
|
167
|
+
systemTools: "The system provides tool discovery and dispatch automatically.",
|
|
168
|
+
heading: "Available tools",
|
|
169
|
+
hint: "Choose which tools this agent can call. Calls still follow the safety authorization settings.",
|
|
170
|
+
mode: "Tool access",
|
|
171
|
+
custom: "Custom",
|
|
172
|
+
allowAll: "Allow all",
|
|
173
|
+
searchLabel: "Search tools",
|
|
174
|
+
searchPlaceholder: "Search name, description, or source",
|
|
175
|
+
filterLabel: "Filter tools",
|
|
176
|
+
filterAll: "All",
|
|
177
|
+
filterSelected: "Selected",
|
|
178
|
+
filterUnselected: "Unselected",
|
|
179
|
+
matching: "· {{count}} matches",
|
|
180
|
+
matching_one: "· {{count}} match",
|
|
181
|
+
noMatches: "No matching tools. Clear the search or filter to see more.",
|
|
182
|
+
clearFilters: "Clear filters",
|
|
183
|
+
expand: "Expand {{group}}",
|
|
184
|
+
collapse: "Collapse {{group}}",
|
|
185
|
+
expandAll: "Expand all",
|
|
186
|
+
collapseAll: "Collapse all",
|
|
187
|
+
selectWholeGroup: "Select or clear all {{count}} tools in this group",
|
|
188
|
+
selectWholeGroup_one: "Select or clear the {{count}} tool in this group",
|
|
189
|
+
unknownSource: "Unknown source",
|
|
190
|
+
unrestricted: "Allow all tools",
|
|
191
|
+
none: "This agent will have no callable ordinary tools",
|
|
192
|
+
selectAll: "Select all of {{group}}",
|
|
193
|
+
chosen: "{{chosen}} of {{total}} chosen",
|
|
194
|
+
unavailable: "Unavailable",
|
|
195
|
+
unavailableHint: "Retained preferences for tools missing from the current catalogue. These tools cannot be called.",
|
|
196
|
+
all: "Select all",
|
|
197
|
+
clear: "Clear"
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
settings: { agents: "Agents" }
|
|
201
|
+
};
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region ui-src/locales/zh-CN.ts
|
|
204
|
+
/** Text owned by this browser capability. */
|
|
205
|
+
var catalogue = {
|
|
206
|
+
runSettings: {
|
|
207
|
+
blocked: "配置恢复尚未完成,新轮次暂时阻断;成功重新读取后恢复。",
|
|
208
|
+
current: "当前限额:每轮 {{steps}} 步;token 预算 {{budget}}。",
|
|
209
|
+
unlimited: "不设上限",
|
|
210
|
+
unconfirmed: "保存结果未确认;已重新读取当前限额,已保留你的草稿。",
|
|
211
|
+
unconfirmedFailed: "保存结果未确认,已保留你的草稿。请重试读取当前限额。",
|
|
212
|
+
changed: "限额已在其他地方更新,已保留你的草稿。",
|
|
213
|
+
title: "运行设置",
|
|
214
|
+
execution: "执行限额",
|
|
215
|
+
maxSteps: "每轮步骤上限",
|
|
216
|
+
budgetEnabled: "限制 token 预算",
|
|
217
|
+
tokenBudget: "累计 token 预算",
|
|
218
|
+
timing: "对之后开始的轮次生效,当前轮次保持原限额。",
|
|
219
|
+
saved: "执行限额已保存",
|
|
220
|
+
positive: "请输入正整数。"
|
|
221
|
+
},
|
|
222
|
+
revisions: {
|
|
223
|
+
title: "版本记录",
|
|
224
|
+
back: "返回配置",
|
|
225
|
+
refresh: "刷新",
|
|
226
|
+
memory: "版本仅保留在本次运行中",
|
|
227
|
+
saved: "该次恢复已保存为 v{{revision}},当前版本为 v{{current}}。新配置按原有时机生效。",
|
|
228
|
+
before: "之前",
|
|
229
|
+
after: "之后",
|
|
230
|
+
loading: "读取中…",
|
|
231
|
+
confirm: "将当前 v{{from}} 恢复为 v{{to}} 的内容,并保存为新版本",
|
|
232
|
+
unchanged: "内容与当前一致,无需恢复",
|
|
233
|
+
restore: "恢复此版本",
|
|
234
|
+
cancel: "取消",
|
|
235
|
+
human: "用户",
|
|
236
|
+
agent: "智能体",
|
|
237
|
+
system: "初始配置",
|
|
238
|
+
current: "当前版本",
|
|
239
|
+
compare: "比较版本",
|
|
240
|
+
sourceMissing: "来源会话不可用",
|
|
241
|
+
source: "查看来源会话",
|
|
242
|
+
more: "加载更早版本",
|
|
243
|
+
noDifference: "两个版本没有差异",
|
|
244
|
+
timing: "提示词与工具选择从下一次模型请求起生效;默认模型用于新建会话。MCP 按现有规则重新连接。",
|
|
245
|
+
fields: {
|
|
246
|
+
name: "名称",
|
|
247
|
+
description: "描述",
|
|
248
|
+
avatar: "头像",
|
|
249
|
+
startsSessions: "可直接对话",
|
|
250
|
+
tools: "工具选择",
|
|
251
|
+
prompts: {
|
|
252
|
+
identity: "身份",
|
|
253
|
+
instructions: "行为规则",
|
|
254
|
+
style: "风格",
|
|
255
|
+
reminder: "提醒"
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
agents: {
|
|
260
|
+
external: "外部智能体",
|
|
261
|
+
add: "添加智能体",
|
|
262
|
+
identifier: "标识符",
|
|
263
|
+
emptyHint: "添加智能体,分别配置默认模型。",
|
|
264
|
+
heading: "智能体",
|
|
265
|
+
hint: "设置新会话使用的智能体及默认模型。",
|
|
266
|
+
name: "名称",
|
|
267
|
+
namePlaceholder: "输入智能体名称",
|
|
268
|
+
tools: "工具",
|
|
269
|
+
/** The one way to see that a tool is missing: a tool reaches the model
|
|
270
|
+
* only inside a message, so an absent one is otherwise indistinguishable
|
|
271
|
+
* from one the model chose not to call. */
|
|
272
|
+
toolsHint: "此智能体可使用的工具。",
|
|
273
|
+
toolsEmpty: "暂无可用工具。",
|
|
274
|
+
none: "暂无智能体",
|
|
275
|
+
tabs: {
|
|
276
|
+
basic: "基本信息",
|
|
277
|
+
prompts: "提示词",
|
|
278
|
+
tools: "工具设置"
|
|
279
|
+
},
|
|
280
|
+
unsaved: "未保存",
|
|
281
|
+
dirty: "有未保存的修改",
|
|
282
|
+
discard: "放弃修改",
|
|
283
|
+
leaveTitle: "放弃未保存的修改?",
|
|
284
|
+
leaveBody: "以下页面的修改尚未保存:",
|
|
285
|
+
leaveStay: "继续编辑",
|
|
286
|
+
changedElsewhere: "已在别处修改",
|
|
287
|
+
loadRemote: "载入新值",
|
|
288
|
+
description: "描述",
|
|
289
|
+
descriptionPlaceholder: "一句话说明这个智能体做什么",
|
|
290
|
+
nameRequired: "名称不能为空",
|
|
291
|
+
descriptionTooLong: "描述不能超过 {{limit}} 个字符",
|
|
292
|
+
startsSessions: "可直接对话",
|
|
293
|
+
remove: "删除",
|
|
294
|
+
removeHint: "删除智能体",
|
|
295
|
+
removeTitle: "删除智能体「{{name}}」?",
|
|
296
|
+
removeBody: "它的会话会保留、仍可阅读,但不能再继续;它的目录 agents/{{id}}/(AGENTS.md 与它自己的技能)会被删除,版本记录、头像、模型参数与文件访问授权一并删除。此操作不能撤销。",
|
|
297
|
+
/** How a session's agent reads once the agent has been removed. */
|
|
298
|
+
deleted: "已删除的智能体",
|
|
299
|
+
startsSessionsAlways: "通用智能体始终可直接对话。",
|
|
300
|
+
directChatOn: "可直接对话:新建会话时可以选它。点一下关闭",
|
|
301
|
+
directChatOff: "不可直接对话:只能被委派。点一下开启",
|
|
302
|
+
avatar: "头像",
|
|
303
|
+
prompts: {
|
|
304
|
+
slots: "提示词插槽",
|
|
305
|
+
identity: "身份",
|
|
306
|
+
instructions: "行为",
|
|
307
|
+
style: "风格",
|
|
308
|
+
reminder: "提醒",
|
|
309
|
+
about: "关于「{{slot}}」",
|
|
310
|
+
purpose: "用途",
|
|
311
|
+
placement: "插入位置",
|
|
312
|
+
example: "例如:{{text}}",
|
|
313
|
+
info: {
|
|
314
|
+
identity: {
|
|
315
|
+
purpose: "写这个智能体是谁:它的角色、人设与口吻。",
|
|
316
|
+
example: "你是一名严谨的代码审查者,说话直接,先讲结论。",
|
|
317
|
+
where: "系统提示词的 Identity 章,紧跟在开头的「You are <名称>」之后,包在 <identity> 标签里。",
|
|
318
|
+
scope: "主会话和委派给这个智能体的会话都带上它。",
|
|
319
|
+
cache: "修改后,已有会话的提示词缓存前缀失效,下一步重新写入缓存。",
|
|
320
|
+
tip: "它只描述角色,不会放宽内置的安全与权限规则。"
|
|
321
|
+
},
|
|
322
|
+
style: {
|
|
323
|
+
purpose: "写这个智能体怎样回复:语气、篇幅与格式。",
|
|
324
|
+
example: "回答不超过三段,代码只给改动的部分。",
|
|
325
|
+
where: "系统提示词的 Tone and output 章,包在 <style> 标签里,优先于该章的内置要求。",
|
|
326
|
+
scope: "主会话和委派给这个智能体的会话都带上它。",
|
|
327
|
+
cache: "修改后,已有会话的提示词缓存前缀失效,下一步重新写入缓存。",
|
|
328
|
+
tip: "它只管表达方式,不会放宽内置的安全与权限规则。"
|
|
329
|
+
},
|
|
330
|
+
reminder: {
|
|
331
|
+
purpose: "写每一步都不能忘的一两条规则。",
|
|
332
|
+
example: "提交代码前必须先运行测试。",
|
|
333
|
+
where: "不在系统提示词里:每一步都附在整段对话之后,包在 <reminder> 标签里,开头是「Standing reminder from the person who set you up:」。",
|
|
334
|
+
scope: "只有主会话带上它,委派给这个智能体的会话不带。",
|
|
335
|
+
cache: "修改它不会让提示词缓存失效。",
|
|
336
|
+
tip: "越短越好,上限 {{limit}} 个字符。"
|
|
337
|
+
},
|
|
338
|
+
instructions: {
|
|
339
|
+
purpose: "写这个智能体的工作规则,补充内置的工作方式;两者冲突时以这里为准。",
|
|
340
|
+
example: "修改数据库结构前先征得我的同意。",
|
|
341
|
+
where: "保存为文件 {{path}},注入系统提示词 Working posture 章的 <instructions> 块。",
|
|
342
|
+
scope: "主会话和委派给这个智能体的会话都带上它。",
|
|
343
|
+
cache: "修改后,已有会话的提示词缓存前缀失效,下一步重新写入缓存。",
|
|
344
|
+
tip: "在主会话里,你要求时智能体也能自己修改这个文件,下一步起生效。"
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
readFailed: "无法读取规则文件,不能编辑:{{reason}}"
|
|
348
|
+
},
|
|
349
|
+
toolSettings: {
|
|
350
|
+
tool: "工具",
|
|
351
|
+
permitted: "允许调用",
|
|
352
|
+
forbidden: "禁止调用",
|
|
353
|
+
preload: "预加载",
|
|
354
|
+
preloadOn: "已预加载,点击改为按需加载",
|
|
355
|
+
preloadOff: "按需加载,点击开启预加载",
|
|
356
|
+
deferred: "按需加载",
|
|
357
|
+
cancelPreload: "取消预加载",
|
|
358
|
+
defaultSuggestion: "默认建议",
|
|
359
|
+
followDefault: "跟随默认",
|
|
360
|
+
customized: "已自定义",
|
|
361
|
+
restoreDefault: "恢复默认",
|
|
362
|
+
resetDefaultsHint: "恢复全部工具的默认调用权限和预加载设置",
|
|
363
|
+
on: "开启",
|
|
364
|
+
off: "关闭",
|
|
365
|
+
preloadInactive: "未允许调用,暂不生效",
|
|
366
|
+
preloadUnavailable: "预加载配置暂不可用,已保存的偏好会保留。",
|
|
367
|
+
systemTools: "系统自动提供工具检索与调用。",
|
|
368
|
+
heading: "可用工具",
|
|
369
|
+
hint: "决定智能体可以调用哪些工具,执行时仍遵循安全授权。",
|
|
370
|
+
mode: "工具授权范围",
|
|
371
|
+
custom: "自定义",
|
|
372
|
+
allowAll: "全部允许",
|
|
373
|
+
searchLabel: "搜索工具",
|
|
374
|
+
searchPlaceholder: "搜索工具名称、说明或来源",
|
|
375
|
+
filterLabel: "筛选工具",
|
|
376
|
+
filterAll: "全部",
|
|
377
|
+
filterSelected: "已选择",
|
|
378
|
+
filterUnselected: "未选择",
|
|
379
|
+
matching: "· 匹配 {{count}} 个",
|
|
380
|
+
noMatches: "没有匹配的工具,试试清除搜索或筛选。",
|
|
381
|
+
clearFilters: "清除筛选",
|
|
382
|
+
expand: "展开 {{group}}",
|
|
383
|
+
collapse: "收起 {{group}}",
|
|
384
|
+
expandAll: "展开全部",
|
|
385
|
+
collapseAll: "收起全部",
|
|
386
|
+
selectWholeGroup: "选择或取消本组全部 {{count}} 个工具",
|
|
387
|
+
unknownSource: "未知来源",
|
|
388
|
+
unrestricted: "授权所有工具调用",
|
|
389
|
+
none: "该智能体将没有可调用的普通工具",
|
|
390
|
+
selectAll: "全选 {{group}}",
|
|
391
|
+
chosen: "已选 {{chosen}} 个,共 {{total}} 个",
|
|
392
|
+
unavailable: "不可用",
|
|
393
|
+
unavailableHint: "已保留配置但当前目录中没有的工具,不能调用。",
|
|
394
|
+
all: "全选",
|
|
395
|
+
clear: "全不选"
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
settings: { agents: "智能体" }
|
|
399
|
+
};
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/tool-names.ts
|
|
402
|
+
/** Canonical names shared by tool registration and browser presentation. */
|
|
403
|
+
var AGENT_TOOL_NAMES = [
|
|
404
|
+
"agent_list",
|
|
405
|
+
"agent_read",
|
|
406
|
+
"agent_update",
|
|
407
|
+
"agent_create"
|
|
408
|
+
];
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region ui-src/metadata.ts
|
|
411
|
+
var CATALOGUES = {
|
|
412
|
+
"en-US": {
|
|
413
|
+
section: "Core capability",
|
|
414
|
+
group: "Agent definition",
|
|
415
|
+
agent_list: "List agents",
|
|
416
|
+
agent_read: "Read agent definition",
|
|
417
|
+
agent_update: "Update agent definition",
|
|
418
|
+
agent_create: "Create agent"
|
|
419
|
+
},
|
|
420
|
+
"zh-CN": {
|
|
421
|
+
section: "核心能力",
|
|
422
|
+
group: "智能体定义",
|
|
423
|
+
agent_list: "列出智能体",
|
|
424
|
+
agent_read: "读取智能体设定",
|
|
425
|
+
agent_update: "更新智能体设定",
|
|
426
|
+
agent_create: "创建智能体"
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
var names = new Set(AGENT_TOOL_NAMES);
|
|
430
|
+
/** Registers presentation facets with the same activation lifetime as the tools. */
|
|
431
|
+
function registerMetadata(ctx) {
|
|
432
|
+
ctx.i18n.register(CATALOGUES, "en-US");
|
|
433
|
+
ctx.i18n.contribute(Object.fromEntries(Object.entries(CATALOGUES).map(([language, catalogue]) => [language, Object.fromEntries([...names].map((tool) => [`transcript.actions.${tool}`, catalogue[tool] ?? tool]))])), "en-US");
|
|
434
|
+
ctx.slots.register("chat.tool.presentation", {
|
|
435
|
+
id: "tool-metadata",
|
|
436
|
+
describe: ({ call }) => {
|
|
437
|
+
if (!names.has(call.name)) return void 0;
|
|
438
|
+
const input = call.input !== null && typeof call.input === "object" ? call.input : {};
|
|
439
|
+
const summary = [
|
|
440
|
+
"path",
|
|
441
|
+
"url",
|
|
442
|
+
"query",
|
|
443
|
+
"command",
|
|
444
|
+
"skill",
|
|
445
|
+
"id",
|
|
446
|
+
"name",
|
|
447
|
+
"task",
|
|
448
|
+
"prompt"
|
|
449
|
+
].flatMap((key) => typeof input[key] === "string" ? [input[key]] : []).slice(0, 2).join(" · ").replace(/\s+/g, " ").slice(0, 240);
|
|
450
|
+
return {
|
|
451
|
+
label: names.has(call.name) ? ctx.i18n.t(call.name) : call.name,
|
|
452
|
+
icon: "hammer",
|
|
453
|
+
summary
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
ctx.slots.register("shell.tools.group", {
|
|
458
|
+
id: "tool-groups",
|
|
459
|
+
describe: (tool) => {
|
|
460
|
+
if (tool.plugin !== ctx.plugin) return void 0;
|
|
461
|
+
return {
|
|
462
|
+
key: `plugin:${ctx.plugin}`,
|
|
463
|
+
label: ctx.i18n.t("group"),
|
|
464
|
+
source: ctx.plugin,
|
|
465
|
+
sectionLabel: ctx.i18n.t("section"),
|
|
466
|
+
sectionOrder: 0,
|
|
467
|
+
order: 0,
|
|
468
|
+
defaultExpanded: true
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region ui-src/components/agent-avatar.tsx
|
|
475
|
+
function AgentAvatar({ agentId, name, avatar, src: override, size = "sm", shape = "circle", decorative = false, tooltip = false, className }) {
|
|
476
|
+
const { t } = useTranslation();
|
|
477
|
+
const client = useGateway();
|
|
478
|
+
const known = useAgents((state) => agentOf(state, agentId));
|
|
479
|
+
const deleted = useAgents((state) => agentDeleted(state, agentId));
|
|
480
|
+
const label = deleted ? t("agents.deleted") : name ?? known?.name ?? agentId;
|
|
481
|
+
const rev = avatar !== void 0 ? avatar : known?.avatar ?? null;
|
|
482
|
+
const fetched = useAgents((state) => pictureOf(state, rev));
|
|
483
|
+
const requestAvatar = useAgents((state) => state.requestAvatar);
|
|
484
|
+
const src = override ?? fetched;
|
|
485
|
+
useEffect(() => {
|
|
486
|
+
if (rev !== null && override === void 0) requestAvatar(client, agentId, rev);
|
|
487
|
+
}, [
|
|
488
|
+
client,
|
|
489
|
+
agentId,
|
|
490
|
+
rev,
|
|
491
|
+
override,
|
|
492
|
+
requestAvatar
|
|
493
|
+
]);
|
|
494
|
+
const face = /* @__PURE__ */ jsx(Avatar, {
|
|
495
|
+
alt: label,
|
|
496
|
+
name: label,
|
|
497
|
+
seed: agentId,
|
|
498
|
+
algorithm: "initials",
|
|
499
|
+
size,
|
|
500
|
+
shape,
|
|
501
|
+
...src === void 0 ? {} : { src },
|
|
502
|
+
"data-slot": "agent-avatar",
|
|
503
|
+
"data-agent": agentId,
|
|
504
|
+
"data-picture": src === void 0 ? "derived" : "uploaded",
|
|
505
|
+
...deleted ? { "data-deleted": true } : {},
|
|
506
|
+
...decorative ? { "aria-hidden": true } : {},
|
|
507
|
+
className: cn("shrink-0", className)
|
|
508
|
+
});
|
|
509
|
+
return tooltip ? /* @__PURE__ */ jsx(TooltipHint, {
|
|
510
|
+
content: label,
|
|
511
|
+
children: face
|
|
512
|
+
}) : face;
|
|
513
|
+
}
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs
|
|
516
|
+
/**
|
|
517
|
+
* @license lucide-react v1.40.0 - ISC
|
|
518
|
+
*
|
|
519
|
+
* This source code is licensed under the ISC license.
|
|
520
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
521
|
+
*/
|
|
522
|
+
var mergeClasses = (...classes) => classes.filter((className, index, array) => {
|
|
523
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
524
|
+
}).join(" ").trim();
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs
|
|
527
|
+
/**
|
|
528
|
+
* @license lucide-react v1.40.0 - ISC
|
|
529
|
+
*
|
|
530
|
+
* This source code is licensed under the ISC license.
|
|
531
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
532
|
+
*/
|
|
533
|
+
var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs
|
|
536
|
+
/**
|
|
537
|
+
* @license lucide-react v1.40.0 - ISC
|
|
538
|
+
*
|
|
539
|
+
* This source code is licensed under the ISC license.
|
|
540
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
541
|
+
*/
|
|
542
|
+
var toCamelCase = (string) => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase());
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs
|
|
545
|
+
/**
|
|
546
|
+
* @license lucide-react v1.40.0 - ISC
|
|
547
|
+
*
|
|
548
|
+
* This source code is licensed under the ISC license.
|
|
549
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
550
|
+
*/
|
|
551
|
+
var toPascalCase = (string) => {
|
|
552
|
+
const camelCase = toCamelCase(string);
|
|
553
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
554
|
+
};
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/defaultAttributes.mjs
|
|
557
|
+
/**
|
|
558
|
+
* @license lucide-react v1.40.0 - ISC
|
|
559
|
+
*
|
|
560
|
+
* This source code is licensed under the ISC license.
|
|
561
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
562
|
+
*/
|
|
563
|
+
var defaultAttributes = {
|
|
564
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
565
|
+
width: 24,
|
|
566
|
+
height: 24,
|
|
567
|
+
viewBox: "0 0 24 24",
|
|
568
|
+
fill: "none",
|
|
569
|
+
stroke: "currentColor",
|
|
570
|
+
strokeWidth: 2,
|
|
571
|
+
strokeLinecap: "round",
|
|
572
|
+
strokeLinejoin: "round"
|
|
573
|
+
};
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs
|
|
576
|
+
/**
|
|
577
|
+
* @license lucide-react v1.40.0 - ISC
|
|
578
|
+
*
|
|
579
|
+
* This source code is licensed under the ISC license.
|
|
580
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
581
|
+
*/
|
|
582
|
+
var hasA11yProp = (props) => {
|
|
583
|
+
for (const prop in props) if (prop.startsWith("aria-") || prop === "role" || prop === "title") return true;
|
|
584
|
+
return false;
|
|
585
|
+
};
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/context.mjs
|
|
588
|
+
/**
|
|
589
|
+
* @license lucide-react v1.40.0 - ISC
|
|
590
|
+
*
|
|
591
|
+
* This source code is licensed under the ISC license.
|
|
592
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
593
|
+
*/
|
|
594
|
+
var LucideContext = createContext({});
|
|
595
|
+
var useLucideContext = () => useContext(LucideContext);
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/Icon.mjs
|
|
598
|
+
/**
|
|
599
|
+
* @license lucide-react v1.40.0 - ISC
|
|
600
|
+
*
|
|
601
|
+
* This source code is licensed under the ISC license.
|
|
602
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
603
|
+
*/
|
|
604
|
+
var Icon = forwardRef(({ color, size, strokeWidth, absoluteStrokeWidth, className = "", children, iconNode, ...rest }, ref) => {
|
|
605
|
+
const { size: contextSize = 24, strokeWidth: contextStrokeWidth = 2, absoluteStrokeWidth: contextAbsoluteStrokeWidth = false, color: contextColor = "currentColor", className: contextClass = "" } = useLucideContext() ?? {};
|
|
606
|
+
const calculatedStrokeWidth = absoluteStrokeWidth ?? contextAbsoluteStrokeWidth ? Number(strokeWidth ?? contextStrokeWidth) * 24 / Number(size ?? contextSize) : strokeWidth ?? contextStrokeWidth;
|
|
607
|
+
return createElement("svg", {
|
|
608
|
+
ref,
|
|
609
|
+
...defaultAttributes,
|
|
610
|
+
width: size ?? contextSize ?? defaultAttributes.width,
|
|
611
|
+
height: size ?? contextSize ?? defaultAttributes.height,
|
|
612
|
+
stroke: color ?? contextColor,
|
|
613
|
+
strokeWidth: calculatedStrokeWidth,
|
|
614
|
+
className: mergeClasses("lucide", contextClass, className),
|
|
615
|
+
...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
|
|
616
|
+
...rest
|
|
617
|
+
}, [...iconNode.map(([tag, attrs]) => createElement(tag, attrs)), ...Array.isArray(children) ? children : [children]]);
|
|
618
|
+
});
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/createLucideIcon.mjs
|
|
621
|
+
/**
|
|
622
|
+
* @license lucide-react v1.40.0 - ISC
|
|
623
|
+
*
|
|
624
|
+
* This source code is licensed under the ISC license.
|
|
625
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
626
|
+
*/
|
|
627
|
+
var createLucideIcon = (iconName, iconNode) => {
|
|
628
|
+
const Component = forwardRef(({ className, ...props }, ref) => createElement(Icon, {
|
|
629
|
+
ref,
|
|
630
|
+
iconNode,
|
|
631
|
+
className: mergeClasses(`lucide-${toKebabCase(toPascalCase(iconName))}`, `lucide-${iconName}`, className),
|
|
632
|
+
...props
|
|
633
|
+
}));
|
|
634
|
+
Component.displayName = toPascalCase(iconName);
|
|
635
|
+
return Component;
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* @license lucide-react v1.40.0 - ISC
|
|
639
|
+
*
|
|
640
|
+
* This source code is licensed under the ISC license.
|
|
641
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
642
|
+
*/
|
|
643
|
+
var Camera = createLucideIcon("camera", [["path", {
|
|
644
|
+
d: "M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",
|
|
645
|
+
key: "18u6gg"
|
|
646
|
+
}], ["circle", {
|
|
647
|
+
cx: "12",
|
|
648
|
+
cy: "13",
|
|
649
|
+
r: "3",
|
|
650
|
+
key: "1vg3eu"
|
|
651
|
+
}]]);
|
|
652
|
+
/**
|
|
653
|
+
* @license lucide-react v1.40.0 - ISC
|
|
654
|
+
*
|
|
655
|
+
* This source code is licensed under the ISC license.
|
|
656
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
657
|
+
*/
|
|
658
|
+
var ChevronDown = createLucideIcon("chevron-down", [["path", {
|
|
659
|
+
d: "m6 9 6 6 6-6",
|
|
660
|
+
key: "qrunsl"
|
|
661
|
+
}]]);
|
|
662
|
+
/**
|
|
663
|
+
* @license lucide-react v1.40.0 - ISC
|
|
664
|
+
*
|
|
665
|
+
* This source code is licensed under the ISC license.
|
|
666
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
667
|
+
*/
|
|
668
|
+
var MessageCircleOff = createLucideIcon("message-circle-off", [
|
|
669
|
+
["path", {
|
|
670
|
+
d: "m2 2 20 20",
|
|
671
|
+
key: "1ooewy"
|
|
672
|
+
}],
|
|
673
|
+
["path", {
|
|
674
|
+
d: "M4.93 4.929a10 10 0 0 0-1.938 11.412 2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 0 0 11.302-1.989",
|
|
675
|
+
key: "7il5tn"
|
|
676
|
+
}],
|
|
677
|
+
["path", {
|
|
678
|
+
d: "M8.35 2.69A10 10 0 0 1 21.3 15.65",
|
|
679
|
+
key: "1pfsoa"
|
|
680
|
+
}]
|
|
681
|
+
]);
|
|
682
|
+
/**
|
|
683
|
+
* @license lucide-react v1.40.0 - ISC
|
|
684
|
+
*
|
|
685
|
+
* This source code is licensed under the ISC license.
|
|
686
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
687
|
+
*/
|
|
688
|
+
var MessageCircle = createLucideIcon("message-circle", [["path", {
|
|
689
|
+
d: "M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",
|
|
690
|
+
key: "1sd12s"
|
|
691
|
+
}]]);
|
|
692
|
+
/**
|
|
693
|
+
* @license lucide-react v1.40.0 - ISC
|
|
694
|
+
*
|
|
695
|
+
* This source code is licensed under the ISC license.
|
|
696
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
697
|
+
*/
|
|
698
|
+
var Puzzle = createLucideIcon("puzzle", [["path", {
|
|
699
|
+
d: "M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",
|
|
700
|
+
key: "w46dr5"
|
|
701
|
+
}]]);
|
|
702
|
+
//#endregion
|
|
703
|
+
//#region ui-src/components/settings/agent/editor.tsx
|
|
704
|
+
/**
|
|
705
|
+
* The agent detail page's one draft and its one save.
|
|
706
|
+
*
|
|
707
|
+
* Base fields, prompt slots, tool access, and opaque owner configuration stay
|
|
708
|
+
* in one draft until Save submits their complete changed values together.
|
|
709
|
+
* Owner fields are validated by their active contributions before that request.
|
|
710
|
+
*
|
|
711
|
+
* A draft remembers the saved value it was started from. When another client
|
|
712
|
+
* changes the agent (`config.agentChanged`, which re-reads the list and the
|
|
713
|
+
* prompt text), a field without a draft simply shows the new value; a field
|
|
714
|
+
* with one keeps it and reports `stale`, and `reload` takes the new value.
|
|
715
|
+
* A draft that the saved value has caught up with is no longer dirty.
|
|
716
|
+
*/
|
|
717
|
+
var SLOT_IDS = [
|
|
718
|
+
"identity",
|
|
719
|
+
"instructions",
|
|
720
|
+
"style",
|
|
721
|
+
"reminder"
|
|
722
|
+
];
|
|
723
|
+
var TAB_IDS = [
|
|
724
|
+
"basic",
|
|
725
|
+
"prompts",
|
|
726
|
+
"tools"
|
|
727
|
+
];
|
|
728
|
+
var TAB_OF = {
|
|
729
|
+
name: "basic",
|
|
730
|
+
description: "basic",
|
|
731
|
+
startsSessions: "basic",
|
|
732
|
+
avatar: "basic",
|
|
733
|
+
tools: "tools",
|
|
734
|
+
"prompt.identity": "prompts",
|
|
735
|
+
"prompt.instructions": "prompts",
|
|
736
|
+
"prompt.style": "prompts",
|
|
737
|
+
"prompt.reminder": "prompts"
|
|
738
|
+
};
|
|
739
|
+
function same(key, a, b) {
|
|
740
|
+
if (key === "avatar") return a === null && b === null || typeof a === "string" && a === b;
|
|
741
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
742
|
+
}
|
|
743
|
+
/** Which field a gateway refusal is about, when its words say so. */
|
|
744
|
+
function fieldOfRefusal(reason) {
|
|
745
|
+
const owner = /^extensionData[.:]([^:]+):/.exec(reason)?.[1];
|
|
746
|
+
if (owner) return `extension:${owner}`;
|
|
747
|
+
if (/avatar/i.test(reason)) return "avatar";
|
|
748
|
+
const slot = /prompt slot (identity|instructions|style|reminder)/i.exec(reason)?.[1];
|
|
749
|
+
if (slot) return `prompt.${slot.toLowerCase()}`;
|
|
750
|
+
if (/AGENTS\.md|rules file|instructions/i.test(reason)) return "prompt.instructions";
|
|
751
|
+
if (/start(s)? sessions|startsSessions/i.test(reason)) return "startsSessions";
|
|
752
|
+
if (/description/i.test(reason)) return "description";
|
|
753
|
+
if (/\btool/i.test(reason)) return "tools";
|
|
754
|
+
if (/\bname\b/i.test(reason) && !/no such agent/i.test(reason)) return "name";
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
var EditorContext = createContext(null);
|
|
758
|
+
function useAgentEditor() {
|
|
759
|
+
const editor = useContext(EditorContext);
|
|
760
|
+
if (editor === null) throw new Error("useAgentEditor outside an agent editor");
|
|
761
|
+
return editor;
|
|
762
|
+
}
|
|
763
|
+
/** The prompt text of one agent, asked again whenever that agent changes;
|
|
764
|
+
* an answer to an older question is dropped. */
|
|
765
|
+
function usePromptSlots(agentId) {
|
|
766
|
+
const read = useGatewayRead("config.agent.promptSlots", {
|
|
767
|
+
agentIds: [agentId],
|
|
768
|
+
maxItemBytes: 262144,
|
|
769
|
+
maxTotalBytes: 8388608
|
|
770
|
+
});
|
|
771
|
+
const member = read.data?.results.find((member) => member.target === agentId);
|
|
772
|
+
return {
|
|
773
|
+
slots: member?.ok ? member.value : null,
|
|
774
|
+
error: read.error ?? (member && !member.ok ? member.error.message : null),
|
|
775
|
+
pending: read.pending,
|
|
776
|
+
reload: read.reload
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
function AgentEditorProvider({ agent: listed, agents, children }) {
|
|
780
|
+
const { slots, error: slotsError, pending: slotsPending, reload: reloadSlots } = usePromptSlots(listed.agentId);
|
|
781
|
+
const contributions = usePlugins((state) => state.contributions);
|
|
782
|
+
const preload = useBrowserService("tool-preload:configuration");
|
|
783
|
+
const preloadOwner = useRef(preload?.owner);
|
|
784
|
+
if (preload) preloadOwner.current = preload.owner;
|
|
785
|
+
const definitions = useGatewayRead("config.prompt.slots");
|
|
786
|
+
const saving = useGatewayAction();
|
|
787
|
+
const remember = useAgents((state) => state.remember);
|
|
788
|
+
const [drafts, setDrafts] = useState(/* @__PURE__ */ new Map());
|
|
789
|
+
const [errors, setErrors] = useState({});
|
|
790
|
+
const [footerError, setFooterError] = useState(null);
|
|
791
|
+
const [reply, setReply] = useState(null);
|
|
792
|
+
const [savedSlots, setSavedSlots] = useState({});
|
|
793
|
+
useEffect(() => {
|
|
794
|
+
setReply(null);
|
|
795
|
+
}, [listed]);
|
|
796
|
+
useEffect(() => {
|
|
797
|
+
setSavedSlots({});
|
|
798
|
+
}, [slots]);
|
|
799
|
+
const agent = reply ?? listed;
|
|
800
|
+
const revisionBase = useRef(agent);
|
|
801
|
+
if (drafts.size === 0) revisionBase.current = agent;
|
|
802
|
+
const saved = useCallback((key) => {
|
|
803
|
+
if (key.startsWith("extension:")) return agent.extensionData?.[key.slice(10)];
|
|
804
|
+
if (key.startsWith("prompt.")) {
|
|
805
|
+
const slot = key.slice(7);
|
|
806
|
+
return savedSlots[slot] ?? slots?.[slot] ?? "";
|
|
807
|
+
}
|
|
808
|
+
return agent[key];
|
|
809
|
+
}, [
|
|
810
|
+
agent,
|
|
811
|
+
slots,
|
|
812
|
+
savedSlots
|
|
813
|
+
]);
|
|
814
|
+
const dirty = useCallback((key) => {
|
|
815
|
+
const draft = drafts.get(key);
|
|
816
|
+
return draft !== void 0 && !same(key, draft.value, saved(key));
|
|
817
|
+
}, [drafts, saved]);
|
|
818
|
+
const value = useCallback((key) => dirty(key) ? drafts.get(key)?.value : saved(key), [
|
|
819
|
+
drafts,
|
|
820
|
+
dirty,
|
|
821
|
+
saved
|
|
822
|
+
]);
|
|
823
|
+
const set = useCallback((key, next) => {
|
|
824
|
+
setDrafts((current) => {
|
|
825
|
+
const copy = new Map(current);
|
|
826
|
+
const base = current.get(key)?.base ?? saved(key);
|
|
827
|
+
if (same(key, next, saved(key))) copy.delete(key);
|
|
828
|
+
else copy.set(key, {
|
|
829
|
+
value: next,
|
|
830
|
+
base
|
|
831
|
+
});
|
|
832
|
+
return copy;
|
|
833
|
+
});
|
|
834
|
+
setErrors((current) => {
|
|
835
|
+
if (!(key in current)) return current;
|
|
836
|
+
const { [key]: _, ...rest } = current;
|
|
837
|
+
return rest;
|
|
838
|
+
});
|
|
839
|
+
}, [saved]);
|
|
840
|
+
const stale = useCallback((key) => {
|
|
841
|
+
const draft = drafts.get(key);
|
|
842
|
+
return draft !== void 0 && dirty(key) && !same(key, draft.base, saved(key));
|
|
843
|
+
}, [
|
|
844
|
+
drafts,
|
|
845
|
+
dirty,
|
|
846
|
+
saved
|
|
847
|
+
]);
|
|
848
|
+
const reload = useCallback((key) => {
|
|
849
|
+
setDrafts((current) => {
|
|
850
|
+
const copy = new Map(current);
|
|
851
|
+
copy.delete(key);
|
|
852
|
+
return copy;
|
|
853
|
+
});
|
|
854
|
+
}, []);
|
|
855
|
+
const limitOf = useCallback((slot) => definitions.data?.find((one) => one.id === slot)?.maxLength, [definitions.data]);
|
|
856
|
+
const invalid = useCallback((key) => {
|
|
857
|
+
if (!dirty(key)) return false;
|
|
858
|
+
const current = value(key);
|
|
859
|
+
if (key.startsWith("extension:")) {
|
|
860
|
+
const owner = key.slice(10);
|
|
861
|
+
if (owner === preloadOwner.current) {
|
|
862
|
+
if (!preload) return true;
|
|
863
|
+
try {
|
|
864
|
+
preload.read(current);
|
|
865
|
+
} catch {
|
|
866
|
+
return true;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return contributions.some((entry) => entry.plugin === owner && (entry.slot === "shell.agentEditor.field" || entry.slot === "shell.agentEditor.tab") && entry.contribution.validate?.(current) != null);
|
|
870
|
+
}
|
|
871
|
+
if (key === "name") return String(current).trim() === "";
|
|
872
|
+
if (key === "description") return codePoints(String(current)) > 500;
|
|
873
|
+
if (key.startsWith("prompt.")) {
|
|
874
|
+
const slot = key.slice(7);
|
|
875
|
+
const limit = limitOf(slot);
|
|
876
|
+
if (slot === "instructions" && slots?.failure !== void 0) return true;
|
|
877
|
+
return limit !== void 0 && codePoints(String(current)) > limit;
|
|
878
|
+
}
|
|
879
|
+
return false;
|
|
880
|
+
}, [
|
|
881
|
+
dirty,
|
|
882
|
+
value,
|
|
883
|
+
limitOf,
|
|
884
|
+
slots,
|
|
885
|
+
contributions,
|
|
886
|
+
preload
|
|
887
|
+
]);
|
|
888
|
+
const dirtyKeys = [.../* @__PURE__ */ new Set([...Object.keys(TAB_OF), ...drafts.keys()])].filter((key) => dirty(key));
|
|
889
|
+
const dirtyTabs = [...new Set(dirtyKeys.map((key) => key.startsWith("extension:") ? (() => {
|
|
890
|
+
const tab = contributions.find((entry) => entry.plugin === key.slice(10) && entry.slot === "shell.agentEditor.tab");
|
|
891
|
+
if (key.slice(10) === preloadOwner.current) return "tools";
|
|
892
|
+
return tab ? `plugin:${tab.key}` : "basic";
|
|
893
|
+
})() : TAB_OF[key]))];
|
|
894
|
+
const canSave = dirtyKeys.length > 0 && !dirtyKeys.some(invalid) && !saving.pending;
|
|
895
|
+
const save = useCallback(async () => {
|
|
896
|
+
if (!canSave) return false;
|
|
897
|
+
const params = {
|
|
898
|
+
agentId: agent.agentId,
|
|
899
|
+
expectedRevision: revisionBase.current.revision,
|
|
900
|
+
expectedContentHash: revisionBase.current.contentHash
|
|
901
|
+
};
|
|
902
|
+
const prompts = {};
|
|
903
|
+
for (const key of dirtyKeys) {
|
|
904
|
+
const current = value(key);
|
|
905
|
+
if (key === "name") params.name = String(current).trim();
|
|
906
|
+
else if (key === "description") params.description = String(current).trim();
|
|
907
|
+
else if (key === "startsSessions") params.startsSessions = current;
|
|
908
|
+
else if (key === "tools") params.tools = current === null ? null : [...current];
|
|
909
|
+
else if (key === "avatar") params.avatar = current === null ? null : current.image;
|
|
910
|
+
else if (key.startsWith("extension:")) params.extensionData = {
|
|
911
|
+
...params.extensionData,
|
|
912
|
+
[key.slice(10)]: current
|
|
913
|
+
};
|
|
914
|
+
else prompts[key.slice(7)] = String(current);
|
|
915
|
+
}
|
|
916
|
+
if (Object.keys(prompts).length > 0) params.prompts = prompts;
|
|
917
|
+
setErrors({});
|
|
918
|
+
setFooterError(null);
|
|
919
|
+
const sent = new Map(dirtyKeys.map((key) => [key, drafts.get(key)]));
|
|
920
|
+
const result = await saving.run((client) => client.call("config.agent.save", params));
|
|
921
|
+
if (!result.ok) return false;
|
|
922
|
+
const avatarDraft = sent.get("avatar")?.value;
|
|
923
|
+
if (avatarDraft && result.data.avatar !== null) remember(result.data.avatar, avatarDraft.preview);
|
|
924
|
+
setReply(result.data);
|
|
925
|
+
setSavedSlots((current) => {
|
|
926
|
+
const next = { ...current };
|
|
927
|
+
for (const [slot, text] of Object.entries(prompts)) next[slot] = text.trim();
|
|
928
|
+
return next;
|
|
929
|
+
});
|
|
930
|
+
setDrafts((current) => {
|
|
931
|
+
const copy = new Map(current);
|
|
932
|
+
for (const [key, draft] of sent) if (copy.get(key) === draft) copy.delete(key);
|
|
933
|
+
return copy;
|
|
934
|
+
});
|
|
935
|
+
return true;
|
|
936
|
+
}, [
|
|
937
|
+
canSave,
|
|
938
|
+
agent.agentId,
|
|
939
|
+
dirtyKeys,
|
|
940
|
+
value,
|
|
941
|
+
drafts,
|
|
942
|
+
saving,
|
|
943
|
+
remember
|
|
944
|
+
]);
|
|
945
|
+
const lastError = useRef(null);
|
|
946
|
+
useEffect(() => {
|
|
947
|
+
if (saving.error === lastError.current) return;
|
|
948
|
+
lastError.current = saving.error;
|
|
949
|
+
if (saving.error === null) return;
|
|
950
|
+
const field = fieldOfRefusal(saving.error);
|
|
951
|
+
if (field !== null && dirty(field)) setErrors({ [field]: saving.error });
|
|
952
|
+
else setFooterError(saving.error);
|
|
953
|
+
}, [saving.error, dirty]);
|
|
954
|
+
const discard = useCallback(() => {
|
|
955
|
+
setDrafts(/* @__PURE__ */ new Map());
|
|
956
|
+
setErrors({});
|
|
957
|
+
setFooterError(null);
|
|
958
|
+
}, []);
|
|
959
|
+
const editor = {
|
|
960
|
+
agent,
|
|
961
|
+
agents,
|
|
962
|
+
slots,
|
|
963
|
+
slotsError,
|
|
964
|
+
slotsPending,
|
|
965
|
+
reloadSlots,
|
|
966
|
+
slotDefinitions: definitions.data,
|
|
967
|
+
value,
|
|
968
|
+
set,
|
|
969
|
+
dirty,
|
|
970
|
+
stale,
|
|
971
|
+
invalid,
|
|
972
|
+
reload,
|
|
973
|
+
dirtyTabs,
|
|
974
|
+
error: (key) => errors[key] ?? null,
|
|
975
|
+
footerError,
|
|
976
|
+
pending: saving.pending,
|
|
977
|
+
canSave,
|
|
978
|
+
save,
|
|
979
|
+
extension: (owner) => ({
|
|
980
|
+
read: (fallback) => value(`extension:${owner}`) ?? fallback,
|
|
981
|
+
update: (next) => set(`extension:${owner}`, next),
|
|
982
|
+
pending: saving.pending,
|
|
983
|
+
tools: value("tools"),
|
|
984
|
+
error: errors[`extension:${owner}`] ?? (dirty(`extension:${owner}`) ? contributions.flatMap((entry) => entry.plugin === owner && (entry.slot === "shell.agentEditor.field" || entry.slot === "shell.agentEditor.tab") ? [entry.contribution.validate?.(value(`extension:${owner}`))] : []).find((message) => message != null) ?? null : null)
|
|
985
|
+
}),
|
|
986
|
+
discard
|
|
987
|
+
};
|
|
988
|
+
return /* @__PURE__ */ jsx(EditorContext.Provider, {
|
|
989
|
+
value: editor,
|
|
990
|
+
children
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
//#endregion
|
|
994
|
+
//#region ui-src/components/settings/agent/parts.tsx
|
|
995
|
+
/** Pieces shared by the agent editor's tabs. */
|
|
996
|
+
/** Says a field with a draft was changed elsewhere, and takes the new value
|
|
997
|
+
* on request. Renders nothing while none of `fields` is stale. */
|
|
998
|
+
function ChangedElsewhere({ fields }) {
|
|
999
|
+
const { t } = useTranslation();
|
|
1000
|
+
const editor = useAgentEditor();
|
|
1001
|
+
const stale = fields.filter((key) => editor.stale(key));
|
|
1002
|
+
if (stale.length === 0) return null;
|
|
1003
|
+
return /* @__PURE__ */ jsx(Alert, {
|
|
1004
|
+
tone: "warning",
|
|
1005
|
+
variant: "soft",
|
|
1006
|
+
"data-slot": "agent-changed-elsewhere",
|
|
1007
|
+
className: "text-xs",
|
|
1008
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1009
|
+
className: "flex flex-wrap items-start justify-between gap-3",
|
|
1010
|
+
children: [/* @__PURE__ */ jsx("span", { children: t("agents.changedElsewhere") }), /* @__PURE__ */ jsx(Button, {
|
|
1011
|
+
size: "sm",
|
|
1012
|
+
variant: "ghost",
|
|
1013
|
+
onClick: () => {
|
|
1014
|
+
for (const key of stale) editor.reload(key);
|
|
1015
|
+
},
|
|
1016
|
+
children: t("agents.loadRemote")
|
|
1017
|
+
})]
|
|
1018
|
+
})
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
//#endregion
|
|
1022
|
+
//#region ui-src/components/settings/agent/basic.tsx
|
|
1023
|
+
/**
|
|
1024
|
+
* The basic-information tab: picture, name, description and the
|
|
1025
|
+
* model cell. Every field, the model cell's included, is part of the editor's
|
|
1026
|
+
* one draft. Whether a person can chat with the agent directly is a toggle on
|
|
1027
|
+
* the agent list, not here.
|
|
1028
|
+
*
|
|
1029
|
+
* The picture is its own upload control: pressing it picks an image, and the
|
|
1030
|
+
* crop shows in place until the save. While the agent has a picture — saved,
|
|
1031
|
+
* or a crop waiting for the save — 恢复默认 beside it drafts the return to the
|
|
1032
|
+
* derived letters face, which the same save applies.
|
|
1033
|
+
*/
|
|
1034
|
+
/** The factory agent, whose session switch the gateway keeps on. */
|
|
1035
|
+
function AvatarField() {
|
|
1036
|
+
const { t } = useTranslation();
|
|
1037
|
+
const editor = useAgentEditor();
|
|
1038
|
+
const { agent } = editor;
|
|
1039
|
+
const picker = useAvatarPicker((base64) => {
|
|
1040
|
+
editor.set("avatar", {
|
|
1041
|
+
image: base64,
|
|
1042
|
+
preview: pngDataUrl(base64)
|
|
1043
|
+
});
|
|
1044
|
+
});
|
|
1045
|
+
const draft = editor.dirty("avatar") ? editor.value("avatar") : void 0;
|
|
1046
|
+
const pictured = draft === void 0 ? agent.avatar !== null : draft !== null;
|
|
1047
|
+
return /* @__PURE__ */ jsxs(Panel, {
|
|
1048
|
+
title: t("agents.avatar"),
|
|
1049
|
+
level: "field",
|
|
1050
|
+
inline: true,
|
|
1051
|
+
children: [
|
|
1052
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1053
|
+
className: "flex min-w-0 items-center",
|
|
1054
|
+
children: [/* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsxs(TooltipTrigger, {
|
|
1055
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
1056
|
+
variant: "plain",
|
|
1057
|
+
"data-slot": "agent-avatar-trigger",
|
|
1058
|
+
className: "group relative size-11 shrink-0 cursor-pointer rounded-pill outline-none focus-visible:ring-3 focus-visible:ring-ring/50",
|
|
1059
|
+
onClick: () => void picker.pick()
|
|
1060
|
+
}),
|
|
1061
|
+
"aria-label": t("avatar.change"),
|
|
1062
|
+
children: [/* @__PURE__ */ jsx(AgentAvatar, {
|
|
1063
|
+
agentId: agent.agentId,
|
|
1064
|
+
name: editor.value("name") || agent.name,
|
|
1065
|
+
avatar: draft === null ? null : agent.avatar,
|
|
1066
|
+
...draft ? { src: draft.preview } : {},
|
|
1067
|
+
size: "lg",
|
|
1068
|
+
decorative: true,
|
|
1069
|
+
className: "size-11 text-sm"
|
|
1070
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1071
|
+
"data-slot": "agent-avatar-overlay",
|
|
1072
|
+
"aria-hidden": "true",
|
|
1073
|
+
className: "absolute inset-0 grid place-items-center rounded-pill bg-foreground/60 text-background opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-visible:opacity-100",
|
|
1074
|
+
children: /* @__PURE__ */ jsx(Camera, {
|
|
1075
|
+
className: "size-4",
|
|
1076
|
+
strokeWidth: 1.75
|
|
1077
|
+
})
|
|
1078
|
+
})]
|
|
1079
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
1080
|
+
side: "top",
|
|
1081
|
+
children: t("avatar.change")
|
|
1082
|
+
})] }), pictured && /* @__PURE__ */ jsx(Button, {
|
|
1083
|
+
variant: "ghost",
|
|
1084
|
+
size: "sm",
|
|
1085
|
+
"data-slot": "agent-avatar-reset",
|
|
1086
|
+
className: "ml-3",
|
|
1087
|
+
onClick: () => {
|
|
1088
|
+
picker.clearRefusal();
|
|
1089
|
+
editor.set("avatar", null);
|
|
1090
|
+
},
|
|
1091
|
+
children: t("avatar.reset")
|
|
1092
|
+
})]
|
|
1093
|
+
}),
|
|
1094
|
+
/* @__PURE__ */ jsx(FormFailure, { reason: picker.refusal ?? editor.error("avatar") }),
|
|
1095
|
+
picker.dialog
|
|
1096
|
+
]
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
function BasicTab() {
|
|
1100
|
+
const { t } = useTranslation();
|
|
1101
|
+
const editor = useAgentEditor();
|
|
1102
|
+
const { agent } = editor;
|
|
1103
|
+
const name = editor.value("name");
|
|
1104
|
+
const description = editor.value("description");
|
|
1105
|
+
const pluginState = usePlugins((state) => state);
|
|
1106
|
+
const registrations = contributionsIn(pluginState, "shell.agentEditor.field");
|
|
1107
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1108
|
+
className: "flex min-w-0 flex-col gap-5",
|
|
1109
|
+
children: [
|
|
1110
|
+
/* @__PURE__ */ jsx(ChangedElsewhere, { fields: [
|
|
1111
|
+
"name",
|
|
1112
|
+
"description",
|
|
1113
|
+
"avatar",
|
|
1114
|
+
...registrations.map((one) => `extension:${one.plugin}`)
|
|
1115
|
+
] }),
|
|
1116
|
+
/* @__PURE__ */ jsx(AvatarField, {}),
|
|
1117
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1118
|
+
label: t("agents.name"),
|
|
1119
|
+
required: true,
|
|
1120
|
+
inline: true,
|
|
1121
|
+
className: "settings-field-row",
|
|
1122
|
+
error: editor.error("name") ?? (editor.invalid("name") ? t("agents.nameRequired") : void 0),
|
|
1123
|
+
children: (binding) => /* @__PURE__ */ jsx(Input, {
|
|
1124
|
+
...binding,
|
|
1125
|
+
value: name,
|
|
1126
|
+
placeholder: t("agents.namePlaceholder"),
|
|
1127
|
+
onChange: (event) => editor.set("name", event.target.value),
|
|
1128
|
+
onKeyDown: (event) => {
|
|
1129
|
+
if (event.key === "Escape" && !event.nativeEvent.isComposing) editor.reload("name");
|
|
1130
|
+
}
|
|
1131
|
+
})
|
|
1132
|
+
}),
|
|
1133
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1134
|
+
label: t("agents.description"),
|
|
1135
|
+
inline: true,
|
|
1136
|
+
className: "settings-field-row",
|
|
1137
|
+
error: editor.error("description") ?? (editor.invalid("description") ? t("agents.descriptionTooLong", { limit: 500 }) : void 0),
|
|
1138
|
+
children: (binding) => /* @__PURE__ */ jsx(Textarea, {
|
|
1139
|
+
...binding,
|
|
1140
|
+
limit: 500,
|
|
1141
|
+
rows: 5,
|
|
1142
|
+
className: "h-[calc(5lh+1rem)] resize-none [field-sizing:fixed]",
|
|
1143
|
+
value: description,
|
|
1144
|
+
placeholder: t("agents.descriptionPlaceholder"),
|
|
1145
|
+
onChange: (event) => editor.set("description", event.target.value)
|
|
1146
|
+
})
|
|
1147
|
+
}),
|
|
1148
|
+
registrations.map((one) => /* @__PURE__ */ jsx(SlotOutlet, {
|
|
1149
|
+
slot: "shell.agentEditor.field",
|
|
1150
|
+
only: one.key,
|
|
1151
|
+
props: {
|
|
1152
|
+
agentId: agent.agentId,
|
|
1153
|
+
editor: editor.extension(one.plugin),
|
|
1154
|
+
errors: { owner: editor.error(`extension:${one.plugin}`) }
|
|
1155
|
+
}
|
|
1156
|
+
}, one.key))
|
|
1157
|
+
]
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region ui-src/components/settings/agent/prompts.tsx
|
|
1162
|
+
/**
|
|
1163
|
+
* The prompt tab: the four slots, one edited at a time, listed as identity,
|
|
1164
|
+
* style, reminder, AGENTS.md — the slots `config.prompt.slots` declares, in
|
|
1165
|
+
* this tab's own order, with their limits from that listing. Each slot keeps
|
|
1166
|
+
* its own draft in the editor, so switching slots asks nothing; the text area
|
|
1167
|
+
* fills the tab and is its only scroller. Above the text area the chosen
|
|
1168
|
+
* slot says what to write there and where the text lands in the model's input.
|
|
1169
|
+
*/
|
|
1170
|
+
/** A dot that says a slot or tab has an unsaved change, to eyes and ears. */
|
|
1171
|
+
/** The slot's identifier as the list's second line. Identifiers, not copy:
|
|
1172
|
+
* the same in every language. Only AGENTS.md is a file. */
|
|
1173
|
+
var SLOT_TAGS = {
|
|
1174
|
+
identity: "IDENTITY Slot",
|
|
1175
|
+
style: "SOUL Slot",
|
|
1176
|
+
reminder: "REMINDER Slot",
|
|
1177
|
+
instructions: "AGENTS.md"
|
|
1178
|
+
};
|
|
1179
|
+
function UnsavedDot() {
|
|
1180
|
+
const { t } = useTranslation();
|
|
1181
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
1182
|
+
"data-slot": "unsaved-dot",
|
|
1183
|
+
className: "inline-flex shrink-0 items-center",
|
|
1184
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1185
|
+
"aria-hidden": "true",
|
|
1186
|
+
className: "size-1.5 rounded-pill bg-primary"
|
|
1187
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1188
|
+
className: "sr-only",
|
|
1189
|
+
children: t("agents.unsaved")
|
|
1190
|
+
})]
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
/** The order this tab lists the slots in. */
|
|
1194
|
+
var DISPLAY_ORDER = [
|
|
1195
|
+
"identity",
|
|
1196
|
+
"style",
|
|
1197
|
+
"reminder",
|
|
1198
|
+
"instructions"
|
|
1199
|
+
];
|
|
1200
|
+
var NOTES = [
|
|
1201
|
+
"where",
|
|
1202
|
+
"scope",
|
|
1203
|
+
"cache",
|
|
1204
|
+
"tip"
|
|
1205
|
+
];
|
|
1206
|
+
/** What the chosen slot is for and where it goes, shown above its editor for
|
|
1207
|
+
* as long as it is chosen: the purpose with an example, then the placement. */
|
|
1208
|
+
function SlotAbout({ slot, limit, path }) {
|
|
1209
|
+
const { t } = useTranslation();
|
|
1210
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1211
|
+
"aria-label": t("agents.prompts.about", { slot: t(`agents.prompts.${slot}`) }),
|
|
1212
|
+
"data-slot": "prompt-slot-about",
|
|
1213
|
+
className: "flex shrink-0 flex-col gap-2 rounded-control bg-muted/60 px-3 py-2.5 text-xs leading-relaxed @xl:flex-row @xl:gap-6",
|
|
1214
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1215
|
+
className: "flex min-w-0 flex-col gap-1 @xl:flex-1",
|
|
1216
|
+
children: [
|
|
1217
|
+
/* @__PURE__ */ jsx("h4", {
|
|
1218
|
+
className: "font-medium text-foreground",
|
|
1219
|
+
children: t("agents.prompts.purpose")
|
|
1220
|
+
}),
|
|
1221
|
+
/* @__PURE__ */ jsx("p", {
|
|
1222
|
+
className: "text-muted-foreground",
|
|
1223
|
+
children: t(`agents.prompts.info.${slot}.purpose`)
|
|
1224
|
+
}),
|
|
1225
|
+
/* @__PURE__ */ jsx("p", {
|
|
1226
|
+
className: "text-muted-foreground",
|
|
1227
|
+
children: t("agents.prompts.example", { text: t(`agents.prompts.info.${slot}.example`) })
|
|
1228
|
+
})
|
|
1229
|
+
]
|
|
1230
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1231
|
+
className: "flex min-w-0 flex-col gap-1 @xl:flex-1",
|
|
1232
|
+
children: [/* @__PURE__ */ jsx("h4", {
|
|
1233
|
+
className: "font-medium text-foreground",
|
|
1234
|
+
children: t("agents.prompts.placement")
|
|
1235
|
+
}), /* @__PURE__ */ jsx("ul", {
|
|
1236
|
+
className: "flex list-disc flex-col gap-0.5 ps-4 text-muted-foreground",
|
|
1237
|
+
children: NOTES.map((note) => /* @__PURE__ */ jsx("li", {
|
|
1238
|
+
className: "break-words",
|
|
1239
|
+
children: t(`agents.prompts.info.${slot}.${note}`, {
|
|
1240
|
+
path,
|
|
1241
|
+
limit: limit ?? ""
|
|
1242
|
+
})
|
|
1243
|
+
}, note))
|
|
1244
|
+
})]
|
|
1245
|
+
})]
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
function PromptsTab() {
|
|
1249
|
+
const { t } = useTranslation();
|
|
1250
|
+
const editor = useAgentEditor();
|
|
1251
|
+
const declared = editor.slotDefinitions?.map((one) => one.id);
|
|
1252
|
+
const order = DISPLAY_ORDER.filter((id) => declared?.includes(id) ?? true);
|
|
1253
|
+
const [picked, setPicked] = useState(order[0] ?? "identity");
|
|
1254
|
+
const slot = order.includes(picked) ? picked : order[0] ?? "identity";
|
|
1255
|
+
const key = `prompt.${slot}`;
|
|
1256
|
+
const limit = editor.slotDefinitions?.find((one) => one.id === slot)?.maxLength;
|
|
1257
|
+
const failure = slot === "instructions" ? editor.slots?.failure : void 0;
|
|
1258
|
+
const label = (id) => t(`agents.prompts.${id}`);
|
|
1259
|
+
const rulesPath = editor.slots?.path ?? `agents/${editor.agent.agentId}/AGENTS.md`;
|
|
1260
|
+
if (editor.slots === null) return /* @__PURE__ */ jsx(ReadFailure, {
|
|
1261
|
+
reason: editor.slotsError,
|
|
1262
|
+
pending: editor.slotsPending,
|
|
1263
|
+
onRetry: editor.reloadSlots
|
|
1264
|
+
});
|
|
1265
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1266
|
+
className: "@container flex min-h-0 min-w-0 flex-1 flex-col gap-3",
|
|
1267
|
+
children: [/* @__PURE__ */ jsx(ChangedElsewhere, { fields: SLOT_IDS.map((id) => `prompt.${id}`) }), /* @__PURE__ */ jsxs("div", {
|
|
1268
|
+
className: "flex min-h-0 min-w-0 flex-1 flex-col gap-4 @2xl:flex-row",
|
|
1269
|
+
children: [
|
|
1270
|
+
/* @__PURE__ */ jsx("nav", {
|
|
1271
|
+
"aria-label": t("agents.prompts.slots"),
|
|
1272
|
+
"data-slot": "prompt-slot-list",
|
|
1273
|
+
className: "hidden w-52 shrink-0 flex-col gap-1 @2xl:flex",
|
|
1274
|
+
children: order.map((id) => /* @__PURE__ */ jsx("div", {
|
|
1275
|
+
"data-slot": "prompt-slot",
|
|
1276
|
+
className: cn("flex min-w-0 items-center gap-1 rounded-control pe-1", id === slot ? "bg-accent text-accent-foreground" : "hover:bg-muted"),
|
|
1277
|
+
children: /* @__PURE__ */ jsxs(Button, {
|
|
1278
|
+
variant: "plain",
|
|
1279
|
+
"data-slot": "prompt-slot-select",
|
|
1280
|
+
"aria-current": id === slot,
|
|
1281
|
+
onClick: () => setPicked(id),
|
|
1282
|
+
className: "flex h-auto min-w-0 flex-1 items-center justify-start gap-2 px-3 py-1.5 text-left",
|
|
1283
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1284
|
+
className: "flex min-w-0 flex-col",
|
|
1285
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1286
|
+
className: "truncate text-sm font-medium",
|
|
1287
|
+
children: label(id)
|
|
1288
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1289
|
+
className: "truncate font-mono text-2xs text-muted-foreground",
|
|
1290
|
+
children: SLOT_TAGS[id]
|
|
1291
|
+
})]
|
|
1292
|
+
}), editor.dirty(`prompt.${id}`) && /* @__PURE__ */ jsx(UnsavedDot, {})]
|
|
1293
|
+
})
|
|
1294
|
+
}, id))
|
|
1295
|
+
}),
|
|
1296
|
+
/* @__PURE__ */ jsx("div", {
|
|
1297
|
+
"data-slot": "prompt-slot-switch",
|
|
1298
|
+
className: "min-w-0 @2xl:hidden",
|
|
1299
|
+
children: /* @__PURE__ */ jsx(Segmented, {
|
|
1300
|
+
fullWidth: true,
|
|
1301
|
+
label: t("agents.prompts.slots"),
|
|
1302
|
+
value: slot,
|
|
1303
|
+
options: order.map((id) => ({
|
|
1304
|
+
value: id,
|
|
1305
|
+
label: editor.dirty(`prompt.${id}`) ? `${label(id)} •` : label(id)
|
|
1306
|
+
})),
|
|
1307
|
+
onSelect: setPicked
|
|
1308
|
+
})
|
|
1309
|
+
}),
|
|
1310
|
+
/* @__PURE__ */ jsxs("section", {
|
|
1311
|
+
"aria-label": label(slot),
|
|
1312
|
+
"data-slot": "prompt-editor",
|
|
1313
|
+
className: "flex min-h-0 min-w-0 flex-1 flex-col gap-2",
|
|
1314
|
+
children: [
|
|
1315
|
+
/* @__PURE__ */ jsx(SlotAbout, {
|
|
1316
|
+
slot,
|
|
1317
|
+
limit,
|
|
1318
|
+
path: rulesPath
|
|
1319
|
+
}),
|
|
1320
|
+
failure !== void 0 && /* @__PURE__ */ jsx(Failure, { reason: t("agents.prompts.readFailed", { reason: failure }) }),
|
|
1321
|
+
/* @__PURE__ */ jsx(Textarea, {
|
|
1322
|
+
"aria-label": label(slot),
|
|
1323
|
+
fill: true,
|
|
1324
|
+
...limit === void 0 ? {} : { limit },
|
|
1325
|
+
readOnly: failure !== void 0,
|
|
1326
|
+
value: editor.value(key),
|
|
1327
|
+
onChange: (event) => editor.set(key, event.target.value),
|
|
1328
|
+
className: "font-mono"
|
|
1329
|
+
}, slot),
|
|
1330
|
+
/* @__PURE__ */ jsx(FormFailure, { reason: editor.error(key) })
|
|
1331
|
+
]
|
|
1332
|
+
})
|
|
1333
|
+
]
|
|
1334
|
+
})]
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
//#endregion
|
|
1338
|
+
//#region ui-src/components/settings/agent/revisions.tsx
|
|
1339
|
+
/** Compact history with explicit comparison and a retryable restore confirmation. */
|
|
1340
|
+
function AgentRevisions({ agentId, onClose, beforeLeave }) {
|
|
1341
|
+
const { t, i18n } = useTranslation();
|
|
1342
|
+
const client = useGateway();
|
|
1343
|
+
const observedRevision = useAgents((state) => state.agents.find((agent) => agent.agentId === agentId)?.revision);
|
|
1344
|
+
const [items, setItems] = useState([]);
|
|
1345
|
+
const [current, setCurrent] = useState(0);
|
|
1346
|
+
const [cursor, setCursor] = useState();
|
|
1347
|
+
const [selected, setSelected] = useState();
|
|
1348
|
+
const [compareTo, setCompareTo] = useState();
|
|
1349
|
+
const [changes, setChanges] = useState([]);
|
|
1350
|
+
const [comparing, setComparing] = useState(false);
|
|
1351
|
+
const [comparisonError, setComparisonError] = useState("");
|
|
1352
|
+
const [preview, setPreview] = useState();
|
|
1353
|
+
const [request, setRequest] = useState();
|
|
1354
|
+
const [busy, setBusy] = useState(false);
|
|
1355
|
+
const [error, setError] = useState("");
|
|
1356
|
+
const [notice, setNotice] = useState("");
|
|
1357
|
+
const [persistent, setPersistent] = useState(true);
|
|
1358
|
+
const generation = useRef(0);
|
|
1359
|
+
const restoring = useRef(false);
|
|
1360
|
+
const comparison = useRef(0);
|
|
1361
|
+
const reason = (cause) => failureText(cause, () => "") ?? "";
|
|
1362
|
+
const read = useCallback(async (next) => {
|
|
1363
|
+
const token = ++generation.current;
|
|
1364
|
+
setBusy(true);
|
|
1365
|
+
setError("");
|
|
1366
|
+
try {
|
|
1367
|
+
const page = await client.call("config.agent.revisions", {
|
|
1368
|
+
agentId,
|
|
1369
|
+
...next ? { cursor: next } : {}
|
|
1370
|
+
});
|
|
1371
|
+
if (generation.current !== token) return;
|
|
1372
|
+
setItems((old) => next ? [...old, ...page.items.filter((row) => !old.some((item) => item.revision === row.revision))] : page.items);
|
|
1373
|
+
setCurrent(page.currentRevision);
|
|
1374
|
+
setCursor(page.nextCursor);
|
|
1375
|
+
setPersistent(page.persistent);
|
|
1376
|
+
} catch (cause) {
|
|
1377
|
+
if (generation.current === token) setError(reason(cause));
|
|
1378
|
+
} finally {
|
|
1379
|
+
if (generation.current === token) setBusy(false);
|
|
1380
|
+
}
|
|
1381
|
+
}, [client, agentId]);
|
|
1382
|
+
useEffect(() => {
|
|
1383
|
+
read();
|
|
1384
|
+
return () => {
|
|
1385
|
+
generation.current++;
|
|
1386
|
+
comparison.current++;
|
|
1387
|
+
};
|
|
1388
|
+
}, [read, observedRevision]);
|
|
1389
|
+
useEffect(() => {
|
|
1390
|
+
let previous = client.connection.status;
|
|
1391
|
+
return client.watchConnection((connection) => {
|
|
1392
|
+
if (connection.status === "online" && previous !== "online") read();
|
|
1393
|
+
previous = connection.status;
|
|
1394
|
+
});
|
|
1395
|
+
}, [client, read]);
|
|
1396
|
+
useEffect(() => {
|
|
1397
|
+
const token = ++comparison.current;
|
|
1398
|
+
setChanges([]);
|
|
1399
|
+
setComparisonError("");
|
|
1400
|
+
setComparing(false);
|
|
1401
|
+
if (selected === void 0 || compareTo === void 0 || selected === compareTo) return;
|
|
1402
|
+
setComparing(true);
|
|
1403
|
+
client.call("config.agent.compareRevisions", {
|
|
1404
|
+
agentId,
|
|
1405
|
+
fromRevision: selected,
|
|
1406
|
+
toRevision: compareTo
|
|
1407
|
+
}).then((result) => {
|
|
1408
|
+
if (token === comparison.current) setChanges(result.changes);
|
|
1409
|
+
}).catch((cause) => {
|
|
1410
|
+
if (token === comparison.current) setComparisonError(reason(cause));
|
|
1411
|
+
}).finally(() => {
|
|
1412
|
+
if (token === comparison.current) setComparing(false);
|
|
1413
|
+
});
|
|
1414
|
+
}, [
|
|
1415
|
+
client,
|
|
1416
|
+
agentId,
|
|
1417
|
+
selected,
|
|
1418
|
+
compareTo,
|
|
1419
|
+
current
|
|
1420
|
+
]);
|
|
1421
|
+
async function prepare(targetRevision) {
|
|
1422
|
+
if (beforeLeave && !await beforeLeave()) return;
|
|
1423
|
+
setBusy(true);
|
|
1424
|
+
setError("");
|
|
1425
|
+
setRequest(void 0);
|
|
1426
|
+
try {
|
|
1427
|
+
const value = await client.call("config.agent.previewRestore", {
|
|
1428
|
+
agentId,
|
|
1429
|
+
targetRevision
|
|
1430
|
+
});
|
|
1431
|
+
setPreview(value);
|
|
1432
|
+
setRequest({
|
|
1433
|
+
targetRevision,
|
|
1434
|
+
expectedRevision: value.expectedRevision,
|
|
1435
|
+
expectedContentHash: value.expectedContentHash,
|
|
1436
|
+
restoreRequestId: uuid()
|
|
1437
|
+
});
|
|
1438
|
+
} catch (cause) {
|
|
1439
|
+
setError(reason(cause));
|
|
1440
|
+
} finally {
|
|
1441
|
+
setBusy(false);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
async function restore() {
|
|
1445
|
+
if (!request || busy || restoring.current) return;
|
|
1446
|
+
restoring.current = true;
|
|
1447
|
+
setBusy(true);
|
|
1448
|
+
setError("");
|
|
1449
|
+
try {
|
|
1450
|
+
const result = await client.call("config.agent.restoreRevision", {
|
|
1451
|
+
agentId,
|
|
1452
|
+
...request
|
|
1453
|
+
});
|
|
1454
|
+
useAgents.getState().consume({
|
|
1455
|
+
kind: "config.agentChanged",
|
|
1456
|
+
agent: result.agent
|
|
1457
|
+
});
|
|
1458
|
+
setNotice(t("revisions.saved", {
|
|
1459
|
+
revision: result.revision,
|
|
1460
|
+
current: result.currentRevision
|
|
1461
|
+
}));
|
|
1462
|
+
setPreview(void 0);
|
|
1463
|
+
setRequest(void 0);
|
|
1464
|
+
await read();
|
|
1465
|
+
} catch (cause) {
|
|
1466
|
+
setError(reason(cause));
|
|
1467
|
+
} finally {
|
|
1468
|
+
restoring.current = false;
|
|
1469
|
+
setBusy(false);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
const diff = (rows) => /* @__PURE__ */ jsx("div", {
|
|
1473
|
+
className: "space-y-4",
|
|
1474
|
+
children: rows.map((row) => /* @__PURE__ */ jsxs("div", {
|
|
1475
|
+
className: "space-y-2",
|
|
1476
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
1477
|
+
className: "text-xs font-medium",
|
|
1478
|
+
children: t(`revisions.fields.${row.path}`, { defaultValue: row.path })
|
|
1479
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1480
|
+
className: "grid gap-2 sm:grid-cols-2",
|
|
1481
|
+
children: [row.before, row.after].map((value, index) => /* @__PURE__ */ jsxs("div", {
|
|
1482
|
+
className: "min-w-0 rounded-control bg-muted/40 p-3",
|
|
1483
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
1484
|
+
className: "mb-2 text-xs text-muted-foreground",
|
|
1485
|
+
children: t(index === 0 ? "revisions.before" : "revisions.after")
|
|
1486
|
+
}), row.path === "avatar" && typeof value === "string" ? /* @__PURE__ */ jsx("img", {
|
|
1487
|
+
src: `data:image/png;base64,${value}`,
|
|
1488
|
+
alt: t(index === 0 ? "revisions.before" : "revisions.after"),
|
|
1489
|
+
className: "size-16 rounded-pill"
|
|
1490
|
+
}) : /* @__PURE__ */ jsx("pre", {
|
|
1491
|
+
className: "max-h-64 overflow-auto whitespace-pre-wrap break-words text-xs",
|
|
1492
|
+
children: typeof value === "string" ? value || "∅" : JSON.stringify(value, null, 2)
|
|
1493
|
+
})]
|
|
1494
|
+
}, index === 0 ? "before" : "after"))
|
|
1495
|
+
})]
|
|
1496
|
+
}, row.path))
|
|
1497
|
+
});
|
|
1498
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1499
|
+
className: "min-h-0 flex-1 space-y-4 overflow-auto px-6 pb-6",
|
|
1500
|
+
"aria-label": t("revisions.title"),
|
|
1501
|
+
children: [
|
|
1502
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1503
|
+
className: "flex items-center justify-between",
|
|
1504
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1505
|
+
variant: "ghost",
|
|
1506
|
+
size: "sm",
|
|
1507
|
+
onClick: onClose,
|
|
1508
|
+
children: t("revisions.back")
|
|
1509
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1510
|
+
variant: "ghost",
|
|
1511
|
+
size: "sm",
|
|
1512
|
+
disabled: busy,
|
|
1513
|
+
onClick: () => void read(),
|
|
1514
|
+
children: t("revisions.refresh")
|
|
1515
|
+
})]
|
|
1516
|
+
}),
|
|
1517
|
+
!persistent && /* @__PURE__ */ jsx("p", {
|
|
1518
|
+
className: "text-xs text-muted-foreground",
|
|
1519
|
+
children: t("revisions.memory")
|
|
1520
|
+
}),
|
|
1521
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
1522
|
+
role: "alert",
|
|
1523
|
+
className: "text-sm text-destructive",
|
|
1524
|
+
children: error
|
|
1525
|
+
}),
|
|
1526
|
+
notice && /* @__PURE__ */ jsx("p", {
|
|
1527
|
+
role: "status",
|
|
1528
|
+
className: "text-sm",
|
|
1529
|
+
children: notice
|
|
1530
|
+
}),
|
|
1531
|
+
busy && /* @__PURE__ */ jsx("p", {
|
|
1532
|
+
role: "status",
|
|
1533
|
+
className: "text-sm text-muted-foreground",
|
|
1534
|
+
children: t("revisions.loading")
|
|
1535
|
+
}),
|
|
1536
|
+
preview && /* @__PURE__ */ jsxs("div", {
|
|
1537
|
+
className: "space-y-4 rounded-control border p-4",
|
|
1538
|
+
children: [
|
|
1539
|
+
/* @__PURE__ */ jsx("h4", { children: t("revisions.confirm", {
|
|
1540
|
+
from: preview.expectedRevision,
|
|
1541
|
+
to: preview.targetRevision
|
|
1542
|
+
}) }),
|
|
1543
|
+
/* @__PURE__ */ jsx("p", {
|
|
1544
|
+
className: "text-xs text-muted-foreground",
|
|
1545
|
+
children: t("revisions.timing")
|
|
1546
|
+
}),
|
|
1547
|
+
diff(preview.changes),
|
|
1548
|
+
preview.blockers.map((blocker) => /* @__PURE__ */ jsxs("p", {
|
|
1549
|
+
className: "text-sm text-destructive",
|
|
1550
|
+
children: [
|
|
1551
|
+
blocker.path,
|
|
1552
|
+
": ",
|
|
1553
|
+
blocker.reason
|
|
1554
|
+
]
|
|
1555
|
+
}, blocker.path + blocker.reason)),
|
|
1556
|
+
preview.unchanged && /* @__PURE__ */ jsx("p", { children: t("revisions.unchanged") }),
|
|
1557
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1558
|
+
className: "flex gap-2",
|
|
1559
|
+
children: [
|
|
1560
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1561
|
+
disabled: busy || preview.unchanged || preview.blockers.length > 0,
|
|
1562
|
+
onClick: () => void restore(),
|
|
1563
|
+
children: t("revisions.restore")
|
|
1564
|
+
}),
|
|
1565
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1566
|
+
variant: "ghost",
|
|
1567
|
+
disabled: busy,
|
|
1568
|
+
onClick: () => void prepare(preview.targetRevision),
|
|
1569
|
+
children: t("revisions.refresh")
|
|
1570
|
+
}),
|
|
1571
|
+
/* @__PURE__ */ jsx(Button, {
|
|
1572
|
+
variant: "ghost",
|
|
1573
|
+
disabled: busy,
|
|
1574
|
+
onClick: () => {
|
|
1575
|
+
setPreview(void 0);
|
|
1576
|
+
setRequest(void 0);
|
|
1577
|
+
},
|
|
1578
|
+
children: t("revisions.cancel")
|
|
1579
|
+
})
|
|
1580
|
+
]
|
|
1581
|
+
})
|
|
1582
|
+
]
|
|
1583
|
+
}),
|
|
1584
|
+
/* @__PURE__ */ jsx("ol", {
|
|
1585
|
+
className: "divide-y",
|
|
1586
|
+
children: items.map((item) => {
|
|
1587
|
+
const expanded = selected === item.revision;
|
|
1588
|
+
const canExpand = items.length > 1 || item.revision !== current || !!item.source.sessionId;
|
|
1589
|
+
const heading = /* @__PURE__ */ jsxs("span", {
|
|
1590
|
+
className: "min-w-0 flex-1 space-y-1",
|
|
1591
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1592
|
+
className: "block text-sm font-medium break-words",
|
|
1593
|
+
children: [
|
|
1594
|
+
"v",
|
|
1595
|
+
item.revision,
|
|
1596
|
+
" · ",
|
|
1597
|
+
item.summary
|
|
1598
|
+
]
|
|
1599
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
1600
|
+
className: "block text-xs text-muted-foreground",
|
|
1601
|
+
children: [
|
|
1602
|
+
new Date(item.createdAt).toLocaleString(i18n.language),
|
|
1603
|
+
" ·",
|
|
1604
|
+
" ",
|
|
1605
|
+
t(`revisions.${item.source.kind}`)
|
|
1606
|
+
]
|
|
1607
|
+
})]
|
|
1608
|
+
});
|
|
1609
|
+
const currentMark = item.revision === current && /* @__PURE__ */ jsx("span", {
|
|
1610
|
+
className: "shrink-0 rounded-control bg-muted px-2 py-1 text-xs text-muted-foreground",
|
|
1611
|
+
children: t("revisions.current")
|
|
1612
|
+
});
|
|
1613
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
1614
|
+
className: "py-2",
|
|
1615
|
+
children: [canExpand ? /* @__PURE__ */ jsxs(Button, {
|
|
1616
|
+
variant: "plain",
|
|
1617
|
+
"aria-expanded": expanded,
|
|
1618
|
+
className: "flex w-full items-center gap-3 rounded-control p-3 text-start hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-ring",
|
|
1619
|
+
onClick: () => {
|
|
1620
|
+
setSelected(expanded ? void 0 : item.revision);
|
|
1621
|
+
setCompareTo(item.revision === current ? items.find((option) => option.revision !== item.revision)?.revision : current);
|
|
1622
|
+
},
|
|
1623
|
+
children: [
|
|
1624
|
+
heading,
|
|
1625
|
+
currentMark,
|
|
1626
|
+
/* @__PURE__ */ jsx(ChevronDown, {
|
|
1627
|
+
"aria-hidden": "true",
|
|
1628
|
+
className: `size-4 shrink-0 text-muted-foreground transition-transform ${expanded ? "rotate-180" : ""}`
|
|
1629
|
+
})
|
|
1630
|
+
]
|
|
1631
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
1632
|
+
className: "flex items-center gap-3 p-3",
|
|
1633
|
+
children: [heading, currentMark]
|
|
1634
|
+
}), expanded && /* @__PURE__ */ jsxs("div", {
|
|
1635
|
+
className: "space-y-4 px-3 pt-3 pb-2",
|
|
1636
|
+
children: [compareTo !== void 0 && compareTo !== item.revision && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("label", {
|
|
1637
|
+
className: "flex flex-wrap items-center gap-2 text-xs text-muted-foreground",
|
|
1638
|
+
children: [
|
|
1639
|
+
t("revisions.compare"),
|
|
1640
|
+
" · v",
|
|
1641
|
+
item.revision,
|
|
1642
|
+
" →",
|
|
1643
|
+
/* @__PURE__ */ jsx(Select, {
|
|
1644
|
+
size: "sm",
|
|
1645
|
+
"aria-label": t("revisions.compare"),
|
|
1646
|
+
value: String(compareTo),
|
|
1647
|
+
onValueChange: (value) => setCompareTo(Number(value)),
|
|
1648
|
+
children: items.filter((option) => option.revision !== item.revision).map((option) => /* @__PURE__ */ jsxs("option", {
|
|
1649
|
+
value: option.revision,
|
|
1650
|
+
children: ["v", option.revision]
|
|
1651
|
+
}, option.revision))
|
|
1652
|
+
})
|
|
1653
|
+
]
|
|
1654
|
+
}), comparing ? /* @__PURE__ */ jsx("p", {
|
|
1655
|
+
role: "status",
|
|
1656
|
+
className: "text-xs text-muted-foreground",
|
|
1657
|
+
children: t("revisions.loading")
|
|
1658
|
+
}) : comparisonError ? /* @__PURE__ */ jsx("p", {
|
|
1659
|
+
role: "alert",
|
|
1660
|
+
className: "text-xs text-destructive",
|
|
1661
|
+
children: comparisonError
|
|
1662
|
+
}) : changes.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
1663
|
+
className: "text-xs text-muted-foreground",
|
|
1664
|
+
children: t("revisions.noDifference")
|
|
1665
|
+
}) : diff(changes)] }), /* @__PURE__ */ jsxs("div", {
|
|
1666
|
+
className: "flex flex-wrap gap-2",
|
|
1667
|
+
children: [item.revision !== current && /* @__PURE__ */ jsx(Button, {
|
|
1668
|
+
variant: "outline",
|
|
1669
|
+
size: "sm",
|
|
1670
|
+
disabled: busy,
|
|
1671
|
+
onClick: () => void prepare(item.revision),
|
|
1672
|
+
children: t("revisions.restore")
|
|
1673
|
+
}), item.source.sessionId && /* @__PURE__ */ jsx(Button, {
|
|
1674
|
+
variant: "ghost",
|
|
1675
|
+
size: "sm",
|
|
1676
|
+
onClick: async () => {
|
|
1677
|
+
if (beforeLeave && !await beforeLeave()) return;
|
|
1678
|
+
if (!await goToSession(client, item.source.sessionId)) setError(t("revisions.sourceMissing"));
|
|
1679
|
+
else useNavigation.getState().openSettings(false);
|
|
1680
|
+
},
|
|
1681
|
+
children: t("revisions.source")
|
|
1682
|
+
})]
|
|
1683
|
+
})]
|
|
1684
|
+
})]
|
|
1685
|
+
}, item.revision);
|
|
1686
|
+
})
|
|
1687
|
+
}),
|
|
1688
|
+
cursor && /* @__PURE__ */ jsx(Button, {
|
|
1689
|
+
variant: "ghost",
|
|
1690
|
+
disabled: busy,
|
|
1691
|
+
onClick: () => void read(cursor),
|
|
1692
|
+
children: t("revisions.more")
|
|
1693
|
+
})
|
|
1694
|
+
]
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
//#endregion
|
|
1698
|
+
//#region ui-src/components/settings/agent/tools.tsx
|
|
1699
|
+
/** Agent tool access and preload preferences grouped from the live tool list. */
|
|
1700
|
+
/** Uses extension metadata without interpreting package names or tool naming conventions. */
|
|
1701
|
+
function groupsOf(tools, describe, unknownSource) {
|
|
1702
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1703
|
+
for (const tool of tools) {
|
|
1704
|
+
const existing = groups.get(tool.plugin);
|
|
1705
|
+
const presentation = describe(tool);
|
|
1706
|
+
const facts = (presentation?.source === tool.plugin ? presentation : existing) ?? {
|
|
1707
|
+
label: tool.plugin || unknownSource,
|
|
1708
|
+
sectionLabel: unknownSource,
|
|
1709
|
+
sectionOrder: 2,
|
|
1710
|
+
order: 0
|
|
1711
|
+
};
|
|
1712
|
+
groups.set(tool.plugin, {
|
|
1713
|
+
...facts,
|
|
1714
|
+
key: `plugin:${tool.plugin}`,
|
|
1715
|
+
source: tool.plugin || unknownSource,
|
|
1716
|
+
tools: [...existing?.tools ?? [], tool]
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1719
|
+
return [...groups.values()].map((group) => ({
|
|
1720
|
+
...group,
|
|
1721
|
+
tools: [...group.tools].sort((a, b) => a.name.localeCompare(b.name))
|
|
1722
|
+
})).sort((a, b) => a.sectionOrder - b.sectionOrder || a.order - b.order || a.label.localeCompare(b.label));
|
|
1723
|
+
}
|
|
1724
|
+
/** Tool permissions and independent preload preferences share the Agent editor transaction. */
|
|
1725
|
+
function ToolsTab() {
|
|
1726
|
+
const { t } = useTranslation();
|
|
1727
|
+
const editor = useAgentEditor();
|
|
1728
|
+
const { agent } = editor;
|
|
1729
|
+
const preload = useBrowserService("tool-preload:configuration");
|
|
1730
|
+
const rememberedOwner = useRef(preload?.owner);
|
|
1731
|
+
if (preload) rememberedOwner.current = preload.owner;
|
|
1732
|
+
const owner = preload?.owner ?? rememberedOwner.current;
|
|
1733
|
+
const ownerKey = owner ? `extension:${owner}` : void 0;
|
|
1734
|
+
const ownerValue = ownerKey ? editor.value(ownerKey) : void 0;
|
|
1735
|
+
const lastOverrides = useRef({});
|
|
1736
|
+
let overrides = lastOverrides.current;
|
|
1737
|
+
let preloadError = null;
|
|
1738
|
+
try {
|
|
1739
|
+
if (preload) {
|
|
1740
|
+
overrides = preload.read(ownerValue);
|
|
1741
|
+
lastOverrides.current = overrides;
|
|
1742
|
+
}
|
|
1743
|
+
} catch (error) {
|
|
1744
|
+
preloadError = error instanceof Error ? error.message : String(error);
|
|
1745
|
+
}
|
|
1746
|
+
const listing = useGatewayRead("config.tool.list", {
|
|
1747
|
+
agentIds: [agent.agentId],
|
|
1748
|
+
maxItemBytes: 262144,
|
|
1749
|
+
maxTotalBytes: 8388608
|
|
1750
|
+
});
|
|
1751
|
+
const member = listing.data?.results.find((one) => one.target === agent.agentId);
|
|
1752
|
+
const tools = member?.ok && member.value.agentId === agent.agentId ? member.value.tools : null;
|
|
1753
|
+
const whitelist = editor.value("tools");
|
|
1754
|
+
const unrestricted = whitelist === null;
|
|
1755
|
+
const permitted = (name) => unrestricted || whitelist.includes(name);
|
|
1756
|
+
const pluginState = usePlugins((state) => state);
|
|
1757
|
+
const presentations = contributionsIn(pluginState, "shell.tools.group");
|
|
1758
|
+
const labels = contributionsIn(pluginState, "chat.tool.presentation");
|
|
1759
|
+
const titleOf = (tool) => {
|
|
1760
|
+
for (const entry of labels) {
|
|
1761
|
+
if (entry.plugin !== tool.plugin) continue;
|
|
1762
|
+
try {
|
|
1763
|
+
const label = entry.contribution.describe({
|
|
1764
|
+
call: {
|
|
1765
|
+
id: tool.name,
|
|
1766
|
+
name: tool.name,
|
|
1767
|
+
input: {}
|
|
1768
|
+
},
|
|
1769
|
+
result: void 0
|
|
1770
|
+
})?.label;
|
|
1771
|
+
if (label) return label;
|
|
1772
|
+
} catch {}
|
|
1773
|
+
}
|
|
1774
|
+
return tool.name;
|
|
1775
|
+
};
|
|
1776
|
+
const groups = groupsOf(tools ?? [], (tool) => presentations.map((one) => one.contribution.describe(tool)).find((value) => value !== void 0), t("agents.toolSettings.unknownSource"));
|
|
1777
|
+
const groupFor = new Map(groups.flatMap((group) => group.tools.map((tool) => [tool.name, group])));
|
|
1778
|
+
const rows = groups.flatMap((group) => group.tools);
|
|
1779
|
+
const known = new Set(rows.map((tool) => tool.name));
|
|
1780
|
+
const unavailable = tools === null ? [] : [.../* @__PURE__ */ new Set([...Object.keys(overrides).filter((name) => !known.has(name)), ...unrestricted ? [] : whitelist.filter((name) => !known.has(name))])];
|
|
1781
|
+
const overridden = (name) => Object.hasOwn(overrides, name);
|
|
1782
|
+
const effective = (tool) => overridden(tool.name) ? overrides[tool.name] === true : tool.preloadDefault;
|
|
1783
|
+
const blocked = !preload || preloadError !== null || editor.pending;
|
|
1784
|
+
const loading = listing.pending && tools === null;
|
|
1785
|
+
function changePermission(names, on) {
|
|
1786
|
+
if (on && whitelist === null) return;
|
|
1787
|
+
const without = (whitelist ?? rows.map((tool) => tool.name)).filter((name) => !names.includes(name));
|
|
1788
|
+
editor.set("tools", on ? [...without, ...names] : without);
|
|
1789
|
+
}
|
|
1790
|
+
function changePreload(names, on) {
|
|
1791
|
+
if (!preload || blocked || !ownerKey) return;
|
|
1792
|
+
const next = { ...overrides };
|
|
1793
|
+
for (const name of names) if (on === void 0) delete next[name];
|
|
1794
|
+
else next[name] = on;
|
|
1795
|
+
editor.set(ownerKey, preload.replace(ownerValue, next));
|
|
1796
|
+
}
|
|
1797
|
+
function resetDefaults() {
|
|
1798
|
+
if (!preload || blocked || !ownerKey) return;
|
|
1799
|
+
const next = preload.replace(ownerValue, {});
|
|
1800
|
+
editor.set("tools", null);
|
|
1801
|
+
editor.set(ownerKey, next);
|
|
1802
|
+
}
|
|
1803
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1804
|
+
className: "@container flex min-w-0 flex-col gap-4",
|
|
1805
|
+
children: [
|
|
1806
|
+
/* @__PURE__ */ jsx(ChangedElsewhere, { fields: ownerKey ? ["tools", ownerKey] : ["tools"] }),
|
|
1807
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1808
|
+
className: "min-w-0",
|
|
1809
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1810
|
+
className: "flex min-w-0 items-center justify-between gap-3",
|
|
1811
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
1812
|
+
className: "text-sm font-semibold",
|
|
1813
|
+
children: t("agents.toolSettings.heading")
|
|
1814
|
+
}), /* @__PURE__ */ jsx(Segmented, {
|
|
1815
|
+
label: t("agents.toolSettings.mode"),
|
|
1816
|
+
value: unrestricted ? "all" : "custom",
|
|
1817
|
+
disabled: tools === null || editor.pending,
|
|
1818
|
+
options: [{
|
|
1819
|
+
value: "custom",
|
|
1820
|
+
label: t("agents.toolSettings.custom")
|
|
1821
|
+
}, {
|
|
1822
|
+
value: "all",
|
|
1823
|
+
label: t("agents.toolSettings.allowAll")
|
|
1824
|
+
}],
|
|
1825
|
+
onSelect: (mode) => editor.set("tools", mode === "all" ? null : rows.filter((tool) => permitted(tool.name)).map((tool) => tool.name))
|
|
1826
|
+
})]
|
|
1827
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
1828
|
+
className: "mt-1 text-xs leading-relaxed text-muted-foreground",
|
|
1829
|
+
children: t("agents.toolSettings.hint")
|
|
1830
|
+
})]
|
|
1831
|
+
}),
|
|
1832
|
+
/* @__PURE__ */ jsx(ReadFailure, {
|
|
1833
|
+
reason: listing.error ?? (member && !member.ok ? member.error.message : null),
|
|
1834
|
+
pending: loading,
|
|
1835
|
+
onRetry: listing.reload
|
|
1836
|
+
}),
|
|
1837
|
+
!preload && /* @__PURE__ */ jsx(Warning, { children: t("agents.toolSettings.preloadUnavailable") }),
|
|
1838
|
+
/* @__PURE__ */ jsx(FormFailure, { reason: preloadError }),
|
|
1839
|
+
(tools !== null || loading) && /* @__PURE__ */ jsx(DataTable, {
|
|
1840
|
+
defaultExpandedGroups: [],
|
|
1841
|
+
ariaLabel: t("agents.toolSettings.heading"),
|
|
1842
|
+
items: rows,
|
|
1843
|
+
keyOf: (tool) => tool.name,
|
|
1844
|
+
labelOf: (tool) => tool.name,
|
|
1845
|
+
searchOf: (tool) => `${titleOf(tool)} ${tool.name} ${tool.description} ${tool.plugin}`,
|
|
1846
|
+
groupSelectionScope: "matching",
|
|
1847
|
+
toolbar: /* @__PURE__ */ jsx(TooltipHint, {
|
|
1848
|
+
content: t("agents.toolSettings.resetDefaultsHint"),
|
|
1849
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
1850
|
+
size: "sm",
|
|
1851
|
+
variant: "ghost",
|
|
1852
|
+
icon: "reset",
|
|
1853
|
+
className: "w-[var(--control-height)] p-0",
|
|
1854
|
+
"aria-label": t("agents.toolSettings.restoreDefault"),
|
|
1855
|
+
disabled: blocked || tools === null,
|
|
1856
|
+
onClick: resetDefaults
|
|
1857
|
+
})
|
|
1858
|
+
}),
|
|
1859
|
+
groupOf: (tool) => {
|
|
1860
|
+
const group = groupFor.get(tool.name);
|
|
1861
|
+
return {
|
|
1862
|
+
key: group.key,
|
|
1863
|
+
label: group.label,
|
|
1864
|
+
hint: group.source
|
|
1865
|
+
};
|
|
1866
|
+
},
|
|
1867
|
+
columns: [{
|
|
1868
|
+
id: "tool",
|
|
1869
|
+
label: t("agents.toolSettings.tool"),
|
|
1870
|
+
render: (tool) => {
|
|
1871
|
+
const title = titleOf(tool);
|
|
1872
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1873
|
+
className: "flex w-full min-w-0 max-w-full flex-col gap-1",
|
|
1874
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1875
|
+
className: "flex min-w-0 items-center gap-2 whitespace-nowrap",
|
|
1876
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1877
|
+
title: tool.name,
|
|
1878
|
+
className: title === tool.name ? "min-w-0 truncate font-mono text-xs text-foreground" : "min-w-0 max-w-[65%] truncate font-mono text-xs text-foreground",
|
|
1879
|
+
children: tool.name
|
|
1880
|
+
}), title !== tool.name && /* @__PURE__ */ jsx("span", {
|
|
1881
|
+
title,
|
|
1882
|
+
className: "min-w-0 truncate text-xs font-medium text-muted-foreground",
|
|
1883
|
+
children: title
|
|
1884
|
+
})]
|
|
1885
|
+
}), /* @__PURE__ */ jsx(TooltipHint, {
|
|
1886
|
+
content: /* @__PURE__ */ jsx("span", {
|
|
1887
|
+
className: "max-h-64 overflow-y-auto whitespace-pre-wrap",
|
|
1888
|
+
children: tool.description
|
|
1889
|
+
}),
|
|
1890
|
+
side: "bottom",
|
|
1891
|
+
closeOnClick: false,
|
|
1892
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
1893
|
+
type: "button",
|
|
1894
|
+
"data-slot": "tool-description",
|
|
1895
|
+
className: "block w-full max-w-full truncate rounded-sm border-0 bg-transparent p-0 text-left text-xs text-muted-foreground focus-visible:outline-2 focus-visible:outline-ring",
|
|
1896
|
+
children: tool.description
|
|
1897
|
+
})
|
|
1898
|
+
})]
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
}, {
|
|
1902
|
+
id: "preload",
|
|
1903
|
+
label: t("agents.toolSettings.preload"),
|
|
1904
|
+
width: "4rem",
|
|
1905
|
+
render: (tool) => /* @__PURE__ */ jsx("div", {
|
|
1906
|
+
className: "flex items-center gap-1",
|
|
1907
|
+
children: /* @__PURE__ */ jsx(TooltipHint, {
|
|
1908
|
+
content: t(effective(tool) ? "agents.toolSettings.preloadOn" : "agents.toolSettings.preloadOff"),
|
|
1909
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
1910
|
+
size: "sm",
|
|
1911
|
+
variant: "ghost",
|
|
1912
|
+
className: effective(tool) ? "w-8 p-0 text-yellow-500" : "w-8 p-0 text-muted-foreground",
|
|
1913
|
+
"aria-label": `${t("agents.toolSettings.preload")} ${tool.name}`,
|
|
1914
|
+
"aria-pressed": effective(tool),
|
|
1915
|
+
disabled: blocked,
|
|
1916
|
+
onClick: () => changePreload([tool.name], !effective(tool)),
|
|
1917
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
1918
|
+
viewBox: "0 0 24 24",
|
|
1919
|
+
width: "16",
|
|
1920
|
+
height: "16",
|
|
1921
|
+
fill: effective(tool) ? "currentColor" : "none",
|
|
1922
|
+
stroke: "currentColor",
|
|
1923
|
+
strokeWidth: "1.6",
|
|
1924
|
+
strokeLinejoin: "round",
|
|
1925
|
+
"aria-hidden": "true",
|
|
1926
|
+
children: /* @__PURE__ */ jsx("path", { d: "m13 2-9 12h7l-1 8 10-13h-7l1-7Z" })
|
|
1927
|
+
})
|
|
1928
|
+
})
|
|
1929
|
+
})
|
|
1930
|
+
})
|
|
1931
|
+
}],
|
|
1932
|
+
selection: {
|
|
1933
|
+
keys: new Set(unrestricted ? rows.map((tool) => tool.name) : whitelist),
|
|
1934
|
+
mode: "enablement",
|
|
1935
|
+
onChange: (next) => {
|
|
1936
|
+
if (unrestricted && rows.every((tool) => next.has(tool.name))) return;
|
|
1937
|
+
editor.set("tools", [...next]);
|
|
1938
|
+
},
|
|
1939
|
+
disabled: editor.pending
|
|
1940
|
+
},
|
|
1941
|
+
loading,
|
|
1942
|
+
size: "sm",
|
|
1943
|
+
empty: /* @__PURE__ */ jsx("p", {
|
|
1944
|
+
className: "text-xs text-muted-foreground",
|
|
1945
|
+
children: t("agents.toolsEmpty")
|
|
1946
|
+
}),
|
|
1947
|
+
className: "w-full min-w-0 [&_table]:table-fixed"
|
|
1948
|
+
}, `${agent.agentId}:${tools === null ? "loading" : "ready"}`),
|
|
1949
|
+
unavailable.length > 0 && /* @__PURE__ */ jsxs("section", {
|
|
1950
|
+
"data-slot": "tool-unavailable",
|
|
1951
|
+
"aria-label": t("agents.toolSettings.unavailable"),
|
|
1952
|
+
className: "rounded-control border border-dashed border-border p-3",
|
|
1953
|
+
children: [
|
|
1954
|
+
/* @__PURE__ */ jsx("h4", {
|
|
1955
|
+
className: "text-xs font-medium",
|
|
1956
|
+
children: t("agents.toolSettings.unavailable")
|
|
1957
|
+
}),
|
|
1958
|
+
/* @__PURE__ */ jsx("p", {
|
|
1959
|
+
className: "mt-1 text-2xs text-muted-foreground",
|
|
1960
|
+
children: t("agents.toolSettings.unavailableHint")
|
|
1961
|
+
}),
|
|
1962
|
+
/* @__PURE__ */ jsx("ul", {
|
|
1963
|
+
className: "mt-2 flex flex-col gap-1",
|
|
1964
|
+
children: unavailable.map((name) => /* @__PURE__ */ jsxs("li", {
|
|
1965
|
+
className: "flex min-w-0 flex-wrap items-center gap-2",
|
|
1966
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1967
|
+
className: "min-w-0 flex-1 break-all font-mono text-xs text-muted-foreground",
|
|
1968
|
+
children: name
|
|
1969
|
+
}), !unrestricted && whitelist.includes(name) && /* @__PURE__ */ jsx(Button, {
|
|
1970
|
+
size: "sm",
|
|
1971
|
+
variant: "ghost",
|
|
1972
|
+
"aria-label": `${t("common.remove")} ${name}`,
|
|
1973
|
+
disabled: editor.pending,
|
|
1974
|
+
onClick: () => changePermission([name], false),
|
|
1975
|
+
children: t("common.remove")
|
|
1976
|
+
})]
|
|
1977
|
+
}, name))
|
|
1978
|
+
})
|
|
1979
|
+
]
|
|
1980
|
+
}),
|
|
1981
|
+
/* @__PURE__ */ jsx(FormFailure, { reason: editor.error("tools") }),
|
|
1982
|
+
ownerKey && /* @__PURE__ */ jsx(FormFailure, { reason: editor.error(ownerKey) })
|
|
1983
|
+
]
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
//#endregion
|
|
1987
|
+
//#region ui-src/components/settings/execution-limits.tsx
|
|
1988
|
+
/** Global execution limits; each successful save applies to subsequent rounds. */
|
|
1989
|
+
function ExecutionLimits({ ctx, registerGuard }) {
|
|
1990
|
+
const host = useGateway();
|
|
1991
|
+
const gateway = ctx?.gateway ?? host;
|
|
1992
|
+
const { t } = useTranslation();
|
|
1993
|
+
const toast = useToast();
|
|
1994
|
+
const translation = useRef(t);
|
|
1995
|
+
translation.current = t;
|
|
1996
|
+
const [saved, setSaved] = useState(null);
|
|
1997
|
+
const [inputKey, setInputKey] = useState(0);
|
|
1998
|
+
const [draft, setDraft] = useState(null);
|
|
1999
|
+
const [readError, setReadError] = useState(null);
|
|
2000
|
+
const [saveError, setSaveError] = useState(null);
|
|
2001
|
+
const [reading, setReading] = useState(true);
|
|
2002
|
+
const [blocked, setBlocked] = useState(false);
|
|
2003
|
+
const [saving, setSaving] = useState(false);
|
|
2004
|
+
const [notice, setNotice] = useState(null);
|
|
2005
|
+
const [online, setOnline] = useState(gateway.connection.status === "online");
|
|
2006
|
+
const latest = useRef({
|
|
2007
|
+
draft,
|
|
2008
|
+
saved,
|
|
2009
|
+
saving
|
|
2010
|
+
});
|
|
2011
|
+
latest.current = {
|
|
2012
|
+
draft,
|
|
2013
|
+
saved,
|
|
2014
|
+
saving
|
|
2015
|
+
};
|
|
2016
|
+
const invalidated = useRef(false);
|
|
2017
|
+
const uncertain = useRef(false);
|
|
2018
|
+
const lifetime = useRef(null);
|
|
2019
|
+
const controller = useRef(null);
|
|
2020
|
+
const reload = useCallback(async (notify = false) => {
|
|
2021
|
+
controller.current?.abort();
|
|
2022
|
+
const request = new AbortController();
|
|
2023
|
+
controller.current = request;
|
|
2024
|
+
setReading(true);
|
|
2025
|
+
setReadError(null);
|
|
2026
|
+
try {
|
|
2027
|
+
const result = await gateway.read("config.limits.get", {}, { signal: request.signal });
|
|
2028
|
+
if (!request.signal.aborted) {
|
|
2029
|
+
setSaved(result.limits);
|
|
2030
|
+
setBlocked(false);
|
|
2031
|
+
if (uncertain.current) setSaveError(translation.current("runSettings.unconfirmed"));
|
|
2032
|
+
if (!(latest.current.draft !== null && JSON.stringify(latest.current.draft) !== JSON.stringify(latest.current.saved))) {
|
|
2033
|
+
setDraft(null);
|
|
2034
|
+
if (JSON.stringify(result.limits) !== JSON.stringify(latest.current.saved)) setInputKey((key) => key + 1);
|
|
2035
|
+
} else if (notify) setNotice("changed");
|
|
2036
|
+
return result.limits;
|
|
2037
|
+
}
|
|
2038
|
+
} catch (error) {
|
|
2039
|
+
if (!request.signal.aborted) {
|
|
2040
|
+
setReadError(error instanceof Error ? error.message : String(error));
|
|
2041
|
+
if (error instanceof Error && "errorCode" in error && error.errorCode === "configuration_recovery_required") setBlocked(true);
|
|
2042
|
+
}
|
|
2043
|
+
} finally {
|
|
2044
|
+
if (!request.signal.aborted) setReading(false);
|
|
2045
|
+
}
|
|
2046
|
+
return null;
|
|
2047
|
+
}, [gateway]);
|
|
2048
|
+
useEffect(() => {
|
|
2049
|
+
lifetime.current = new AbortController();
|
|
2050
|
+
reload();
|
|
2051
|
+
return () => {
|
|
2052
|
+
controller.current?.abort();
|
|
2053
|
+
lifetime.current?.abort();
|
|
2054
|
+
};
|
|
2055
|
+
}, [reload]);
|
|
2056
|
+
useEffect(() => {
|
|
2057
|
+
let previous = gateway.connection.status;
|
|
2058
|
+
const off = gateway.watchConnection((state) => {
|
|
2059
|
+
setOnline(state.status === "online");
|
|
2060
|
+
if (state.status === "online" && previous !== "online") reload(true);
|
|
2061
|
+
previous = state.status;
|
|
2062
|
+
});
|
|
2063
|
+
const stop = gateway.subscribe((frame) => {
|
|
2064
|
+
if (frame.kind !== "config.limitsChanged") return;
|
|
2065
|
+
if (latest.current.saving) invalidated.current = true;
|
|
2066
|
+
else reload(true);
|
|
2067
|
+
});
|
|
2068
|
+
return () => {
|
|
2069
|
+
off();
|
|
2070
|
+
stop();
|
|
2071
|
+
};
|
|
2072
|
+
}, [gateway, reload]);
|
|
2073
|
+
const guardState = useRef({
|
|
2074
|
+
dirty: false,
|
|
2075
|
+
pending: false
|
|
2076
|
+
});
|
|
2077
|
+
guardState.current = {
|
|
2078
|
+
dirty: draft !== null && JSON.stringify(draft) !== JSON.stringify(saved),
|
|
2079
|
+
pending: saving
|
|
2080
|
+
};
|
|
2081
|
+
useEffect(() => {
|
|
2082
|
+
registerGuard(() => guardState.current);
|
|
2083
|
+
return () => registerGuard(null);
|
|
2084
|
+
}, [registerGuard]);
|
|
2085
|
+
const values = draft ?? saved;
|
|
2086
|
+
const positive = (value) => value !== void 0 && Number.isSafeInteger(value) && value > 0;
|
|
2087
|
+
async function save() {
|
|
2088
|
+
if (values === null || saving || !online || reading || readError !== null || !positive(values.maxSteps) || values.tokenBudget !== void 0 && !positive(values.tokenBudget)) return;
|
|
2089
|
+
let committed = false;
|
|
2090
|
+
setSaving(true);
|
|
2091
|
+
uncertain.current = false;
|
|
2092
|
+
setSaveError(null);
|
|
2093
|
+
try {
|
|
2094
|
+
const result = await gateway.call("config.limits.set", { limits: values }, {
|
|
2095
|
+
timeoutMs: 5e3,
|
|
2096
|
+
signal: lifetime.current?.signal
|
|
2097
|
+
});
|
|
2098
|
+
if (lifetime.current?.signal.aborted) return;
|
|
2099
|
+
controller.current?.abort();
|
|
2100
|
+
setReading(false);
|
|
2101
|
+
committed = true;
|
|
2102
|
+
setSaved(result.limits);
|
|
2103
|
+
setDraft(null);
|
|
2104
|
+
setNotice(null);
|
|
2105
|
+
toast.add({
|
|
2106
|
+
tone: "success",
|
|
2107
|
+
title: t("runSettings.saved")
|
|
2108
|
+
});
|
|
2109
|
+
} catch (error) {
|
|
2110
|
+
if (lifetime.current?.signal.aborted) return;
|
|
2111
|
+
const code = error instanceof Error && "errorCode" in error ? error.errorCode : void 0;
|
|
2112
|
+
const refused = error instanceof Error && "failure" in error && error.failure === "refused";
|
|
2113
|
+
if (code === "configuration_write_rejected" || refused && code !== "configuration_recovery_required") setSaveError(error instanceof Error ? error.message : String(error));
|
|
2114
|
+
else {
|
|
2115
|
+
uncertain.current = true;
|
|
2116
|
+
if (code === "configuration_recovery_required") setBlocked(true);
|
|
2117
|
+
setSaveError(t("runSettings.unconfirmedFailed"));
|
|
2118
|
+
await reload();
|
|
2119
|
+
}
|
|
2120
|
+
} finally {
|
|
2121
|
+
if (!lifetime.current?.signal.aborted) {
|
|
2122
|
+
setSaving(false);
|
|
2123
|
+
if (invalidated.current) {
|
|
2124
|
+
invalidated.current = false;
|
|
2125
|
+
reload(!committed);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2131
|
+
/* @__PURE__ */ jsx(ReadFailure, {
|
|
2132
|
+
reason: readError,
|
|
2133
|
+
pending: reading && values === null,
|
|
2134
|
+
onRetry: () => void reload()
|
|
2135
|
+
}),
|
|
2136
|
+
blocked && !reading && /* @__PURE__ */ jsx("p", {
|
|
2137
|
+
role: "alert",
|
|
2138
|
+
className: "text-xs text-destructive",
|
|
2139
|
+
children: t("runSettings.blocked")
|
|
2140
|
+
}),
|
|
2141
|
+
values && /* @__PURE__ */ jsxs("form", {
|
|
2142
|
+
className: "flex flex-col gap-6",
|
|
2143
|
+
onSubmit: (event) => {
|
|
2144
|
+
event.preventDefault();
|
|
2145
|
+
save();
|
|
2146
|
+
},
|
|
2147
|
+
children: [
|
|
2148
|
+
/* @__PURE__ */ jsx("p", {
|
|
2149
|
+
className: "text-xs text-muted-foreground",
|
|
2150
|
+
children: t("runSettings.timing")
|
|
2151
|
+
}),
|
|
2152
|
+
/* @__PURE__ */ jsx(Field, {
|
|
2153
|
+
label: t("runSettings.maxSteps"),
|
|
2154
|
+
required: true,
|
|
2155
|
+
inline: true,
|
|
2156
|
+
error: positive(values.maxSteps) ? void 0 : t("runSettings.positive"),
|
|
2157
|
+
children: (binding) => /* @__PURE__ */ jsx(InputNumber, {
|
|
2158
|
+
...binding,
|
|
2159
|
+
label: t("runSettings.maxSteps"),
|
|
2160
|
+
incrementLabel: t("common.increase"),
|
|
2161
|
+
decrementLabel: t("common.decrease"),
|
|
2162
|
+
min: 1,
|
|
2163
|
+
step: 1,
|
|
2164
|
+
disabled: saving,
|
|
2165
|
+
value: values.maxSteps || null,
|
|
2166
|
+
onValueChange: (value) => setDraft({
|
|
2167
|
+
...values,
|
|
2168
|
+
maxSteps: value ?? 0
|
|
2169
|
+
})
|
|
2170
|
+
}, inputKey)
|
|
2171
|
+
}),
|
|
2172
|
+
/* @__PURE__ */ jsx(Field, {
|
|
2173
|
+
label: t("runSettings.budgetEnabled"),
|
|
2174
|
+
inline: true,
|
|
2175
|
+
children: (binding) => /* @__PURE__ */ jsx(Switch, {
|
|
2176
|
+
...binding,
|
|
2177
|
+
checked: values.tokenBudget !== void 0,
|
|
2178
|
+
disabled: saving,
|
|
2179
|
+
onCheckedChange: (checked) => setDraft(checked ? {
|
|
2180
|
+
...values,
|
|
2181
|
+
tokenBudget: 0
|
|
2182
|
+
} : { maxSteps: values.maxSteps })
|
|
2183
|
+
})
|
|
2184
|
+
}),
|
|
2185
|
+
values.tokenBudget !== void 0 && /* @__PURE__ */ jsx(Field, {
|
|
2186
|
+
label: t("runSettings.tokenBudget"),
|
|
2187
|
+
required: true,
|
|
2188
|
+
inline: true,
|
|
2189
|
+
error: positive(values.tokenBudget) ? void 0 : t("runSettings.positive"),
|
|
2190
|
+
children: (binding) => /* @__PURE__ */ jsx(InputNumber, {
|
|
2191
|
+
...binding,
|
|
2192
|
+
label: t("runSettings.tokenBudget"),
|
|
2193
|
+
incrementLabel: t("common.increase"),
|
|
2194
|
+
decrementLabel: t("common.decrease"),
|
|
2195
|
+
min: 1,
|
|
2196
|
+
step: 1,
|
|
2197
|
+
disabled: saving,
|
|
2198
|
+
value: values.tokenBudget || null,
|
|
2199
|
+
onValueChange: (value) => setDraft({
|
|
2200
|
+
...values,
|
|
2201
|
+
tokenBudget: value ?? 0
|
|
2202
|
+
})
|
|
2203
|
+
}, inputKey)
|
|
2204
|
+
}),
|
|
2205
|
+
notice && /* @__PURE__ */ jsx("p", {
|
|
2206
|
+
role: "status",
|
|
2207
|
+
className: "text-xs text-muted-foreground",
|
|
2208
|
+
children: t("runSettings.changed")
|
|
2209
|
+
}),
|
|
2210
|
+
/* @__PURE__ */ jsx(FormFailure, { reason: saveError }),
|
|
2211
|
+
uncertain.current && saved && readError === null && !reading && /* @__PURE__ */ jsx("p", {
|
|
2212
|
+
className: "text-xs text-muted-foreground",
|
|
2213
|
+
children: t("runSettings.current", {
|
|
2214
|
+
steps: saved.maxSteps,
|
|
2215
|
+
budget: saved.tokenBudget ?? t("runSettings.unlimited")
|
|
2216
|
+
})
|
|
2217
|
+
}),
|
|
2218
|
+
/* @__PURE__ */ jsx("div", {
|
|
2219
|
+
className: "flex justify-end",
|
|
2220
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2221
|
+
variant: "primary",
|
|
2222
|
+
type: "submit",
|
|
2223
|
+
loading: saving,
|
|
2224
|
+
disabled: !online || reading || readError !== null || !positive(values.maxSteps) || values.tokenBudget !== void 0 && !positive(values.tokenBudget),
|
|
2225
|
+
children: t("common.save")
|
|
2226
|
+
})
|
|
2227
|
+
})
|
|
2228
|
+
]
|
|
2229
|
+
})
|
|
2230
|
+
] });
|
|
2231
|
+
}
|
|
2232
|
+
//#endregion
|
|
2233
|
+
//#region ui-src/components/settings/run-settings.tsx
|
|
2234
|
+
/** Fixed global running-settings entrance owned by Agent management. */
|
|
2235
|
+
function RunSettingsButton({ ctx }) {
|
|
2236
|
+
const { t } = useTranslation();
|
|
2237
|
+
const [open, setOpen] = useState(false);
|
|
2238
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(TooltipHint, {
|
|
2239
|
+
content: t("runSettings.title"),
|
|
2240
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2241
|
+
variant: "plain",
|
|
2242
|
+
size: "sm",
|
|
2243
|
+
icon: "settings",
|
|
2244
|
+
"aria-label": t("runSettings.title"),
|
|
2245
|
+
onClick: () => setOpen(true)
|
|
2246
|
+
})
|
|
2247
|
+
}), open && /* @__PURE__ */ jsx(RunSettingsDialog, {
|
|
2248
|
+
ctx,
|
|
2249
|
+
onClose: () => setOpen(false)
|
|
2250
|
+
})] });
|
|
2251
|
+
}
|
|
2252
|
+
/** One retained page per live owner, with a shared close guard and independent saves. */
|
|
2253
|
+
function RunSettingsDialog({ ctx, onClose }) {
|
|
2254
|
+
const { t } = useTranslation();
|
|
2255
|
+
const state = usePlugins((state) => state);
|
|
2256
|
+
const pages = contributionsIn(state, "shell.agentRunSettings.section");
|
|
2257
|
+
const [selected, setSelected] = useState("execution");
|
|
2258
|
+
const shown = selected === "execution" || pages.some((page) => page.key === selected) ? selected : "execution";
|
|
2259
|
+
useEffect(() => {
|
|
2260
|
+
if (shown !== selected) setSelected(shown);
|
|
2261
|
+
}, [shown, selected]);
|
|
2262
|
+
const guards = useRef(/* @__PURE__ */ new Map());
|
|
2263
|
+
const register = useCallback((key, guard) => {
|
|
2264
|
+
if (guard) guards.current.set(key, guard);
|
|
2265
|
+
else guards.current.delete(key);
|
|
2266
|
+
}, []);
|
|
2267
|
+
const labels = new Map([["execution", t("runSettings.execution")], ...pages.map((page) => [page.key, resolveLabel(page.contribution.label, page.key)])]);
|
|
2268
|
+
const [asking, setAsking] = useState(null);
|
|
2269
|
+
const requestClose = () => {
|
|
2270
|
+
const valid = [...guards.current].filter(([key]) => labels.has(key));
|
|
2271
|
+
if (valid.some(([, guard]) => guard().pending)) return;
|
|
2272
|
+
const dirty = valid.filter(([, guard]) => guard().dirty).map(([key]) => key);
|
|
2273
|
+
if (dirty.length > 0) setAsking(dirty);
|
|
2274
|
+
else onClose();
|
|
2275
|
+
};
|
|
2276
|
+
const executionGuard = useCallback((guard) => register("execution", guard), [register]);
|
|
2277
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Dialog, {
|
|
2278
|
+
open: true,
|
|
2279
|
+
onOpenChange: (next) => {
|
|
2280
|
+
if (!next) requestClose();
|
|
2281
|
+
},
|
|
2282
|
+
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
2283
|
+
closeLabel: t("settings.close"),
|
|
2284
|
+
overlayProps: {
|
|
2285
|
+
forceRender: true,
|
|
2286
|
+
className: "file-picker-backdrop"
|
|
2287
|
+
},
|
|
2288
|
+
className: "@container max-w-md gap-5 p-6 sm:max-w-md",
|
|
2289
|
+
children: [/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("runSettings.title") }) }), /* @__PURE__ */ jsxs(Tabs, {
|
|
2290
|
+
value: shown,
|
|
2291
|
+
onValueChange: (next) => setSelected(String(next)),
|
|
2292
|
+
children: [
|
|
2293
|
+
/* @__PURE__ */ jsxs(TabsList, {
|
|
2294
|
+
"aria-label": t("runSettings.title"),
|
|
2295
|
+
className: "mb-5 w-full",
|
|
2296
|
+
children: [/* @__PURE__ */ jsx(TabsTrigger, {
|
|
2297
|
+
value: "execution",
|
|
2298
|
+
children: t("runSettings.execution")
|
|
2299
|
+
}), pages.map((page) => /* @__PURE__ */ jsx(TabsTrigger, {
|
|
2300
|
+
value: page.key,
|
|
2301
|
+
"data-plugin": page.owner,
|
|
2302
|
+
children: labels.get(page.key)
|
|
2303
|
+
}, page.key))]
|
|
2304
|
+
}),
|
|
2305
|
+
/* @__PURE__ */ jsx(TabsContent, {
|
|
2306
|
+
value: "execution",
|
|
2307
|
+
keepMounted: true,
|
|
2308
|
+
children: /* @__PURE__ */ jsx(ExecutionLimits, {
|
|
2309
|
+
ctx,
|
|
2310
|
+
registerGuard: executionGuard,
|
|
2311
|
+
requestClose
|
|
2312
|
+
})
|
|
2313
|
+
}),
|
|
2314
|
+
pages.map((page) => /* @__PURE__ */ jsx(TabsContent, {
|
|
2315
|
+
value: page.key,
|
|
2316
|
+
keepMounted: true,
|
|
2317
|
+
children: /* @__PURE__ */ jsx(OwnerSection, {
|
|
2318
|
+
registrationKey: page.key,
|
|
2319
|
+
register,
|
|
2320
|
+
requestClose
|
|
2321
|
+
})
|
|
2322
|
+
}, page.key))
|
|
2323
|
+
]
|
|
2324
|
+
})]
|
|
2325
|
+
})
|
|
2326
|
+
}), /* @__PURE__ */ jsxs(AlertDialog, {
|
|
2327
|
+
open: asking !== null,
|
|
2328
|
+
onOpenChange: (next) => {
|
|
2329
|
+
if (!next) setAsking(null);
|
|
2330
|
+
},
|
|
2331
|
+
title: t("agents.leaveTitle"),
|
|
2332
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
2333
|
+
variant: "ghost",
|
|
2334
|
+
onClick: () => setAsking(null),
|
|
2335
|
+
children: t("agents.leaveStay")
|
|
2336
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2337
|
+
variant: "destructive",
|
|
2338
|
+
onClick: onClose,
|
|
2339
|
+
children: t("agents.discard")
|
|
2340
|
+
})] }),
|
|
2341
|
+
children: [/* @__PURE__ */ jsx("p", { children: t("agents.leaveBody") }), /* @__PURE__ */ jsx("ul", {
|
|
2342
|
+
className: "list-disc ps-5",
|
|
2343
|
+
children: asking?.filter((key) => labels.has(key)).map((key) => /* @__PURE__ */ jsx("li", { children: labels.get(key) }, key))
|
|
2344
|
+
})]
|
|
2345
|
+
})] });
|
|
2346
|
+
}
|
|
2347
|
+
function OwnerSection({ registrationKey, register, requestClose }) {
|
|
2348
|
+
const registerGuard = useCallback((guard) => register(registrationKey, guard), [registrationKey, register]);
|
|
2349
|
+
useEffect(() => () => registerGuard(null), [registerGuard]);
|
|
2350
|
+
return /* @__PURE__ */ jsx(SlotOutlet, {
|
|
2351
|
+
slot: "shell.agentRunSettings.section",
|
|
2352
|
+
only: registrationKey,
|
|
2353
|
+
props: {
|
|
2354
|
+
registerGuard,
|
|
2355
|
+
requestClose
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2359
|
+
//#endregion
|
|
2360
|
+
//#region ui-src/components/settings/agents.tsx
|
|
2361
|
+
/**
|
|
2362
|
+
* The agent library in two columns, the way the model and MCP categories are
|
|
2363
|
+
* laid out: the agents down the left, each row's direct-chat switch and delete
|
|
2364
|
+
* on hover, the plugin sections below them and the add button at the foot; the
|
|
2365
|
+
* chosen agent's editor on the right. Moving to another row asks every guard
|
|
2366
|
+
* this page holds first — the editor's, a plugin tab's, a plugin section's —
|
|
2367
|
+
* so a draft is never dropped by a click on the list.
|
|
2368
|
+
*/
|
|
2369
|
+
function AgentsPanel({ register, chapters = [], ctx } = {}) {
|
|
2370
|
+
const { t } = useTranslation();
|
|
2371
|
+
const agents = useGatewayRead("config.agent.list");
|
|
2372
|
+
const [adding, setAdding] = useState(false);
|
|
2373
|
+
const [picked, setPicked] = useState(null);
|
|
2374
|
+
const guards = useRef(/* @__PURE__ */ new Map());
|
|
2375
|
+
const registerHere = useCallback((key, guard) => {
|
|
2376
|
+
if (guard) guards.current.set(key, guard);
|
|
2377
|
+
else guards.current.delete(key);
|
|
2378
|
+
register?.(key, guard);
|
|
2379
|
+
}, [register]);
|
|
2380
|
+
const choice = picked?.kind === "chapter" && chapters.some((one) => one.key === picked.key) ? picked : picked?.kind === "agent" && agents.data?.some((one) => one.agentId === picked.id) ? picked : agents.data?.[0] ? {
|
|
2381
|
+
kind: "agent",
|
|
2382
|
+
id: agents.data[0].agentId
|
|
2383
|
+
} : null;
|
|
2384
|
+
const selected = choice?.kind === "agent" ? agents.data?.find((one) => one.agentId === choice.id) : void 0;
|
|
2385
|
+
const chapter = choice?.kind === "chapter" ? chapters.find((one) => one.key === choice.key) : void 0;
|
|
2386
|
+
async function choose(next) {
|
|
2387
|
+
if (choice && choice.kind === next.kind && (next.kind === "agent" ? choice.kind === "agent" && choice.id === next.id : choice.kind === "chapter" && choice.key === next.key)) return;
|
|
2388
|
+
for (const guard of [...guards.current.values()]) if (!await guard()) return;
|
|
2389
|
+
setPicked(next);
|
|
2390
|
+
}
|
|
2391
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2392
|
+
className: "ag",
|
|
2393
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2394
|
+
className: "ag-shell",
|
|
2395
|
+
children: [/* @__PURE__ */ jsxs("section", {
|
|
2396
|
+
className: "ag-list",
|
|
2397
|
+
"aria-labelledby": "agents-list-title",
|
|
2398
|
+
children: [
|
|
2399
|
+
/* @__PURE__ */ jsxs("header", {
|
|
2400
|
+
className: "ag-list-title",
|
|
2401
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
2402
|
+
id: "agents-list-title",
|
|
2403
|
+
children: t("settings.agents")
|
|
2404
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
2405
|
+
className: "flex items-center gap-2",
|
|
2406
|
+
children: [/* @__PURE__ */ jsx(SlotOutlet, {
|
|
2407
|
+
slot: "shell.agentEditor.action",
|
|
2408
|
+
props: {}
|
|
2409
|
+
}), /* @__PURE__ */ jsx(RunSettingsButton, { ctx })]
|
|
2410
|
+
})]
|
|
2411
|
+
}),
|
|
2412
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2413
|
+
className: "ag-rows",
|
|
2414
|
+
children: [
|
|
2415
|
+
/* @__PURE__ */ jsx(ReadFailure, {
|
|
2416
|
+
reason: agents.error,
|
|
2417
|
+
pending: agents.pending && agents.data === null,
|
|
2418
|
+
onRetry: agents.reload
|
|
2419
|
+
}),
|
|
2420
|
+
agents.data?.length === 0 && /* @__PURE__ */ jsx(EmptyState, { title: t("agents.none") }),
|
|
2421
|
+
/* @__PURE__ */ jsx("ul", {
|
|
2422
|
+
className: "ag-group",
|
|
2423
|
+
children: agents.data?.map((agent) => {
|
|
2424
|
+
const active = choice?.kind === "agent" && choice.id === agent.agentId;
|
|
2425
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
2426
|
+
className: "ag-row",
|
|
2427
|
+
"data-active": active || void 0,
|
|
2428
|
+
children: [/* @__PURE__ */ jsxs(Button, {
|
|
2429
|
+
variant: "plain",
|
|
2430
|
+
className: "ag-row-open",
|
|
2431
|
+
"aria-label": agent.name,
|
|
2432
|
+
"aria-current": active || void 0,
|
|
2433
|
+
onClick: () => void choose({
|
|
2434
|
+
kind: "agent",
|
|
2435
|
+
id: agent.agentId
|
|
2436
|
+
}),
|
|
2437
|
+
children: [/* @__PURE__ */ jsx(AgentAvatar, {
|
|
2438
|
+
agentId: agent.agentId,
|
|
2439
|
+
name: agent.name,
|
|
2440
|
+
avatar: agent.avatar,
|
|
2441
|
+
decorative: true
|
|
2442
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
2443
|
+
className: "ag-row-name",
|
|
2444
|
+
children: [/* @__PURE__ */ jsx("strong", { children: agent.name }), /* @__PURE__ */ jsx("small", { children: agent.agentId })]
|
|
2445
|
+
})]
|
|
2446
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
2447
|
+
className: "ag-row-actions",
|
|
2448
|
+
children: [/* @__PURE__ */ jsx(DirectChatToggle, {
|
|
2449
|
+
agent,
|
|
2450
|
+
onChanged: agents.reload
|
|
2451
|
+
}), agent.agentId !== GENERAL_PURPOSE_ID && /* @__PURE__ */ jsx(RemoveAgentButton, {
|
|
2452
|
+
agent,
|
|
2453
|
+
onRemoved: agents.reload
|
|
2454
|
+
})]
|
|
2455
|
+
})]
|
|
2456
|
+
}, agent.agentId);
|
|
2457
|
+
})
|
|
2458
|
+
}),
|
|
2459
|
+
chapters.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
|
|
2460
|
+
className: "ag-group-title",
|
|
2461
|
+
children: t("agents.external")
|
|
2462
|
+
}), /* @__PURE__ */ jsx("ul", {
|
|
2463
|
+
className: "ag-group",
|
|
2464
|
+
children: chapters.map((one) => {
|
|
2465
|
+
const active = choice?.kind === "chapter" && choice.key === one.key;
|
|
2466
|
+
const Icon = one.icon ? PLUGIN_ICONS[one.icon] : Puzzle;
|
|
2467
|
+
return /* @__PURE__ */ jsx("li", {
|
|
2468
|
+
className: "ag-row",
|
|
2469
|
+
"data-active": active || void 0,
|
|
2470
|
+
children: /* @__PURE__ */ jsxs(Button, {
|
|
2471
|
+
variant: "plain",
|
|
2472
|
+
className: "ag-row-open",
|
|
2473
|
+
"data-plugin": one.owner,
|
|
2474
|
+
"aria-current": active || void 0,
|
|
2475
|
+
onClick: () => void choose({
|
|
2476
|
+
kind: "chapter",
|
|
2477
|
+
key: one.key
|
|
2478
|
+
}),
|
|
2479
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2480
|
+
className: "ag-chapter-icon",
|
|
2481
|
+
"aria-hidden": "true",
|
|
2482
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
2483
|
+
className: "size-4",
|
|
2484
|
+
strokeWidth: 1.75
|
|
2485
|
+
})
|
|
2486
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2487
|
+
className: "ag-row-name",
|
|
2488
|
+
children: /* @__PURE__ */ jsx("strong", { children: one.label })
|
|
2489
|
+
})]
|
|
2490
|
+
})
|
|
2491
|
+
}, one.key);
|
|
2492
|
+
})
|
|
2493
|
+
})] })
|
|
2494
|
+
]
|
|
2495
|
+
}),
|
|
2496
|
+
/* @__PURE__ */ jsx("div", {
|
|
2497
|
+
className: "ag-list-foot",
|
|
2498
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2499
|
+
variant: "outline",
|
|
2500
|
+
icon: "plus",
|
|
2501
|
+
className: "w-full",
|
|
2502
|
+
onClick: () => setAdding(true),
|
|
2503
|
+
children: t("agents.add")
|
|
2504
|
+
})
|
|
2505
|
+
})
|
|
2506
|
+
]
|
|
2507
|
+
}), selected && agents.data ? /* @__PURE__ */ jsx(AgentEditorProvider, {
|
|
2508
|
+
agent: selected,
|
|
2509
|
+
agents: agents.data,
|
|
2510
|
+
children: /* @__PURE__ */ jsx(AgentDetail, { register: registerHere })
|
|
2511
|
+
}, selected.agentId) : chapter ? /* @__PURE__ */ jsxs("section", {
|
|
2512
|
+
className: "ag-detail",
|
|
2513
|
+
"aria-label": chapter.label,
|
|
2514
|
+
children: [/* @__PURE__ */ jsx("header", {
|
|
2515
|
+
className: "ag-detail-header",
|
|
2516
|
+
children: /* @__PURE__ */ jsx("h3", { children: chapter.label })
|
|
2517
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
2518
|
+
className: "ag-chapter-body",
|
|
2519
|
+
children: chapter.content(registerHere)
|
|
2520
|
+
})]
|
|
2521
|
+
}, chapter.key) : /* @__PURE__ */ jsx("section", { className: "ag-detail ag-detail-empty" })]
|
|
2522
|
+
}), adding && /* @__PURE__ */ jsx(CreateAgent, {
|
|
2523
|
+
onClose: () => setAdding(false),
|
|
2524
|
+
onCreated: (created) => {
|
|
2525
|
+
agents.reload();
|
|
2526
|
+
setAdding(false);
|
|
2527
|
+
setPicked({
|
|
2528
|
+
kind: "agent",
|
|
2529
|
+
id: created
|
|
2530
|
+
});
|
|
2531
|
+
}
|
|
2532
|
+
})]
|
|
2533
|
+
});
|
|
2534
|
+
}
|
|
2535
|
+
/** Where a plugin tab is by default among the others; the same default a
|
|
2536
|
+
* settings category takes. */
|
|
2537
|
+
var PLUGIN_TAB_ORDER = 100;
|
|
2538
|
+
/** The `shell.agentEditor.tab` registrations mountable now, in the order
|
|
2539
|
+
* their tabs follow the four fixed ones. A crashed registration is already
|
|
2540
|
+
* left out by `contributionsIn`, so its tab goes with it. */
|
|
2541
|
+
function usePluginTabs() {
|
|
2542
|
+
const contributions = usePlugins((state) => state.contributions);
|
|
2543
|
+
const crashed = usePlugins((state) => state.crashed);
|
|
2544
|
+
return useMemo(() => contributionsIn({
|
|
2545
|
+
contributions,
|
|
2546
|
+
crashed
|
|
2547
|
+
}, "shell.agentEditor.tab").toSorted((a, b) => (a.contribution.order ?? PLUGIN_TAB_ORDER) - (b.contribution.order ?? PLUGIN_TAB_ORDER) || a.sequence - b.sequence), [contributions, crashed]);
|
|
2548
|
+
}
|
|
2549
|
+
/** One plugin tab's content, keeping its leave guard under its own key and
|
|
2550
|
+
* withdrawing it when the tab goes, whether by unload or by crash. */
|
|
2551
|
+
function PluginAgentTab({ registrationKey, agentId, register }) {
|
|
2552
|
+
const onLeaveGuard = useCallback((guard) => register(registrationKey, guard), [register, registrationKey]);
|
|
2553
|
+
useEffect(() => () => register(registrationKey, null), [register, registrationKey]);
|
|
2554
|
+
const editor = useAgentEditor();
|
|
2555
|
+
const registration = usePlugins((state) => state.contributions.find((one) => one.key === registrationKey));
|
|
2556
|
+
if (!registration) return /* @__PURE__ */ jsx(Fragment, {});
|
|
2557
|
+
return /* @__PURE__ */ jsx(SlotOutlet, {
|
|
2558
|
+
slot: "shell.agentEditor.tab",
|
|
2559
|
+
only: registrationKey,
|
|
2560
|
+
props: {
|
|
2561
|
+
agentId,
|
|
2562
|
+
onLeaveGuard,
|
|
2563
|
+
editor: editor.extension(registration.plugin)
|
|
2564
|
+
}
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
/** All configuration tabs share one draft and footer. Leaving checks plugin
|
|
2568
|
+
* resource operations first, then asks once about the shared unsaved changes. */
|
|
2569
|
+
function AgentDetail({ register }) {
|
|
2570
|
+
const { t } = useTranslation();
|
|
2571
|
+
const editor = useAgentEditor();
|
|
2572
|
+
const { agent } = editor;
|
|
2573
|
+
const [tab, setTab] = useState("basic");
|
|
2574
|
+
const [history, setHistory] = useState(false);
|
|
2575
|
+
const pluginTabs = usePluginTabs();
|
|
2576
|
+
const shownTab = [...TAB_IDS, ...pluginTabs.map((one) => pluginTabValue(one.key))].includes(tab) ? tab : "basic";
|
|
2577
|
+
useEffect(() => {
|
|
2578
|
+
if (shownTab !== tab) setTab(shownTab);
|
|
2579
|
+
}, [shownTab, tab]);
|
|
2580
|
+
const pluginGuards = useRef(/* @__PURE__ */ new Map());
|
|
2581
|
+
const registerPluginGuard = useCallback((key, guard) => {
|
|
2582
|
+
if (guard) pluginGuards.current.set(key, guard);
|
|
2583
|
+
else pluginGuards.current.delete(key);
|
|
2584
|
+
}, []);
|
|
2585
|
+
const [asking, setAsking] = useState(null);
|
|
2586
|
+
const latest = useRef(editor);
|
|
2587
|
+
latest.current = editor;
|
|
2588
|
+
const guard = useCallback(async () => {
|
|
2589
|
+
for (const pluginGuard of [...pluginGuards.current.values()]) if (!await pluginGuard()) return false;
|
|
2590
|
+
const dirtyTabs = latest.current.dirtyTabs;
|
|
2591
|
+
if (dirtyTabs.length === 0) return true;
|
|
2592
|
+
return new Promise((resolve) => setAsking({
|
|
2593
|
+
tabs: dirtyTabs,
|
|
2594
|
+
resolve
|
|
2595
|
+
}));
|
|
2596
|
+
}, []);
|
|
2597
|
+
useEffect(() => {
|
|
2598
|
+
if (!register) return;
|
|
2599
|
+
const key = `agent-detail:${agent.agentId}`;
|
|
2600
|
+
register(key, guard);
|
|
2601
|
+
return () => register(key, null);
|
|
2602
|
+
}, [
|
|
2603
|
+
register,
|
|
2604
|
+
guard,
|
|
2605
|
+
agent.agentId
|
|
2606
|
+
]);
|
|
2607
|
+
function answer(leave) {
|
|
2608
|
+
if (leave) latest.current.discard();
|
|
2609
|
+
asking?.resolve(leave);
|
|
2610
|
+
setAsking(null);
|
|
2611
|
+
}
|
|
2612
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
2613
|
+
className: "ag-detail",
|
|
2614
|
+
"aria-label": agent.name,
|
|
2615
|
+
children: [
|
|
2616
|
+
/* @__PURE__ */ jsxs("header", {
|
|
2617
|
+
className: "ag-detail-header",
|
|
2618
|
+
children: [
|
|
2619
|
+
/* @__PURE__ */ jsx(AgentAvatar, {
|
|
2620
|
+
agentId: agent.agentId,
|
|
2621
|
+
name: agent.name,
|
|
2622
|
+
avatar: agent.avatar,
|
|
2623
|
+
decorative: true
|
|
2624
|
+
}),
|
|
2625
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2626
|
+
className: "ag-grow",
|
|
2627
|
+
children: [/* @__PURE__ */ jsx("h3", { children: agent.name }), /* @__PURE__ */ jsx("small", {
|
|
2628
|
+
"data-slot": "agent-id",
|
|
2629
|
+
children: agent.agentId
|
|
2630
|
+
})]
|
|
2631
|
+
}),
|
|
2632
|
+
/* @__PURE__ */ jsx(Button, {
|
|
2633
|
+
variant: "text",
|
|
2634
|
+
className: "min-w-0 text-right",
|
|
2635
|
+
onClick: () => setHistory(true),
|
|
2636
|
+
children: t("revisions.title")
|
|
2637
|
+
})
|
|
2638
|
+
]
|
|
2639
|
+
}),
|
|
2640
|
+
/* @__PURE__ */ jsxs(Tabs, {
|
|
2641
|
+
value: shownTab,
|
|
2642
|
+
onValueChange: (next) => setTab(String(next)),
|
|
2643
|
+
className: history ? "hidden" : "ag-tabs",
|
|
2644
|
+
onKeyDown: (event) => {
|
|
2645
|
+
if (event.key === "Enter" && (event.metaKey || event.ctrlKey) && editor.canSave) {
|
|
2646
|
+
event.preventDefault();
|
|
2647
|
+
editor.save();
|
|
2648
|
+
}
|
|
2649
|
+
},
|
|
2650
|
+
children: [
|
|
2651
|
+
/* @__PURE__ */ jsxs(TabsList, {
|
|
2652
|
+
"aria-label": agent.name,
|
|
2653
|
+
className: "ag-tabs-list",
|
|
2654
|
+
children: [TAB_IDS.map((id) => /* @__PURE__ */ jsx(TabsTrigger, {
|
|
2655
|
+
value: id,
|
|
2656
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
2657
|
+
className: "inline-flex items-center gap-1.5",
|
|
2658
|
+
children: [t(`agents.tabs.${id}`), editor.dirtyTabs.includes(id) && /* @__PURE__ */ jsx(UnsavedDot, {})]
|
|
2659
|
+
})
|
|
2660
|
+
}, id)), pluginTabs.map((one) => /* @__PURE__ */ jsx(TabsTrigger, {
|
|
2661
|
+
value: pluginTabValue(one.key),
|
|
2662
|
+
"data-plugin": one.owner,
|
|
2663
|
+
children: /* @__PURE__ */ jsxs("span", {
|
|
2664
|
+
className: "inline-flex items-center gap-1.5",
|
|
2665
|
+
children: [resolveLabel(one.contribution.title, one.contribution.id), editor.dirty(`extension:${one.plugin}`) && /* @__PURE__ */ jsx(UnsavedDot, {})]
|
|
2666
|
+
})
|
|
2667
|
+
}, one.key))]
|
|
2668
|
+
}),
|
|
2669
|
+
/* @__PURE__ */ jsx(TabsContent, {
|
|
2670
|
+
value: "basic",
|
|
2671
|
+
className: "ag-tab",
|
|
2672
|
+
children: /* @__PURE__ */ jsx(BasicTab, {})
|
|
2673
|
+
}),
|
|
2674
|
+
/* @__PURE__ */ jsx(TabsContent, {
|
|
2675
|
+
value: "prompts",
|
|
2676
|
+
className: "ag-tab ag-tab-fill",
|
|
2677
|
+
children: /* @__PURE__ */ jsx(PromptsTab, {})
|
|
2678
|
+
}),
|
|
2679
|
+
/* @__PURE__ */ jsx(TabsContent, {
|
|
2680
|
+
value: "tools",
|
|
2681
|
+
className: "ag-tab",
|
|
2682
|
+
children: /* @__PURE__ */ jsx(ToolsTab, {})
|
|
2683
|
+
}),
|
|
2684
|
+
pluginTabs.map((one) => /* @__PURE__ */ jsx(TabsContent, {
|
|
2685
|
+
value: pluginTabValue(one.key),
|
|
2686
|
+
keepMounted: true,
|
|
2687
|
+
className: cn("ag-tab", one.contribution.className),
|
|
2688
|
+
children: /* @__PURE__ */ jsx(PluginAgentTab, {
|
|
2689
|
+
registrationKey: one.key,
|
|
2690
|
+
agentId: agent.agentId,
|
|
2691
|
+
register: registerPluginGuard
|
|
2692
|
+
})
|
|
2693
|
+
}, one.key))
|
|
2694
|
+
]
|
|
2695
|
+
}),
|
|
2696
|
+
!history && /* @__PURE__ */ jsx(AgentFooter, {}),
|
|
2697
|
+
history && /* @__PURE__ */ jsx(AgentRevisions, {
|
|
2698
|
+
agentId: agent.agentId,
|
|
2699
|
+
onClose: () => setHistory(false),
|
|
2700
|
+
beforeLeave: guard
|
|
2701
|
+
}),
|
|
2702
|
+
/* @__PURE__ */ jsxs(AlertDialog, {
|
|
2703
|
+
open: asking !== null,
|
|
2704
|
+
onOpenChange: (open) => {
|
|
2705
|
+
if (!open) answer(false);
|
|
2706
|
+
},
|
|
2707
|
+
title: t("agents.leaveTitle"),
|
|
2708
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
2709
|
+
variant: "ghost",
|
|
2710
|
+
onClick: () => answer(false),
|
|
2711
|
+
children: t("agents.leaveStay")
|
|
2712
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2713
|
+
variant: "destructive",
|
|
2714
|
+
onClick: () => answer(true),
|
|
2715
|
+
children: t("agents.discard")
|
|
2716
|
+
})] }),
|
|
2717
|
+
children: [/* @__PURE__ */ jsx("p", { children: t("agents.leaveBody") }), /* @__PURE__ */ jsx("ul", {
|
|
2718
|
+
"data-slot": "agent-leave-tabs",
|
|
2719
|
+
className: "list-disc ps-5",
|
|
2720
|
+
children: asking?.tabs.map((id) => /* @__PURE__ */ jsx("li", { children: pluginTabs.find((one) => pluginTabValue(one.key) === id) ? resolveLabel(pluginTabs.find((one) => pluginTabValue(one.key) === id).contribution.title, id) : t(`agents.tabs.${id}`) }, id))
|
|
2721
|
+
})]
|
|
2722
|
+
})
|
|
2723
|
+
]
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
/** Discard and save under every tab, one equal share each, with the refusal
|
|
2727
|
+
* of the last save above them. */
|
|
2728
|
+
function AgentFooter() {
|
|
2729
|
+
const { t } = useTranslation();
|
|
2730
|
+
const editor = useAgentEditor();
|
|
2731
|
+
const dirty = editor.dirtyTabs.length > 0;
|
|
2732
|
+
return /* @__PURE__ */ jsxs("footer", {
|
|
2733
|
+
"data-slot": "agent-footer",
|
|
2734
|
+
className: "ag-footer",
|
|
2735
|
+
children: [editor.footerError !== null && /* @__PURE__ */ jsx(FormFailure, { reason: editor.footerError }), /* @__PURE__ */ jsxs("div", {
|
|
2736
|
+
className: "ag-footer-actions",
|
|
2737
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
2738
|
+
variant: "outline",
|
|
2739
|
+
icon: "reset",
|
|
2740
|
+
disabled: !dirty || editor.pending,
|
|
2741
|
+
onClick: editor.discard,
|
|
2742
|
+
children: t("agents.discard")
|
|
2743
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2744
|
+
variant: "primary",
|
|
2745
|
+
icon: "save",
|
|
2746
|
+
disabled: !editor.canSave,
|
|
2747
|
+
onClick: () => void editor.save(),
|
|
2748
|
+
children: t(editor.pending ? "common.working" : "common.save")
|
|
2749
|
+
})]
|
|
2750
|
+
})]
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
function CreateAgent({ onClose, onCreated }) {
|
|
2754
|
+
const { t } = useTranslation();
|
|
2755
|
+
const create = useGatewayAction();
|
|
2756
|
+
const [name, setName] = useState("");
|
|
2757
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
2758
|
+
open: true,
|
|
2759
|
+
onOpenChange: (open) => {
|
|
2760
|
+
if (!open && !create.pending) onClose();
|
|
2761
|
+
},
|
|
2762
|
+
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
2763
|
+
closeLabel: t("settings.close"),
|
|
2764
|
+
overlayProps: {
|
|
2765
|
+
forceRender: true,
|
|
2766
|
+
className: "file-picker-backdrop"
|
|
2767
|
+
},
|
|
2768
|
+
className: "@container max-w-md gap-5 p-6 sm:max-w-md",
|
|
2769
|
+
children: [/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("agents.add") }) }), /* @__PURE__ */ jsxs("form", {
|
|
2770
|
+
className: "flex min-w-0 flex-col gap-5",
|
|
2771
|
+
onSubmit: (event) => {
|
|
2772
|
+
event.preventDefault();
|
|
2773
|
+
if (!name.trim() || create.pending) return;
|
|
2774
|
+
create.run((client) => client.call("config.agent.create", { name: name.trim() })).then((result) => {
|
|
2775
|
+
if (result.ok) onCreated(result.data.agentId);
|
|
2776
|
+
});
|
|
2777
|
+
},
|
|
2778
|
+
children: [
|
|
2779
|
+
/* @__PURE__ */ jsx(Field, {
|
|
2780
|
+
label: t("agents.name"),
|
|
2781
|
+
required: true,
|
|
2782
|
+
inline: true,
|
|
2783
|
+
children: ({ id }) => /* @__PURE__ */ jsx(Input, {
|
|
2784
|
+
id,
|
|
2785
|
+
value: name,
|
|
2786
|
+
disabled: create.pending,
|
|
2787
|
+
placeholder: t("agents.namePlaceholder"),
|
|
2788
|
+
onChange: (event) => setName(event.target.value)
|
|
2789
|
+
})
|
|
2790
|
+
}),
|
|
2791
|
+
/* @__PURE__ */ jsx(FormFailure, { reason: create.error }),
|
|
2792
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2793
|
+
className: "flex justify-end gap-2",
|
|
2794
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
2795
|
+
type: "button",
|
|
2796
|
+
variant: "ghost",
|
|
2797
|
+
disabled: create.pending,
|
|
2798
|
+
onClick: onClose,
|
|
2799
|
+
children: t("common.cancel")
|
|
2800
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2801
|
+
variant: "primary",
|
|
2802
|
+
type: "submit",
|
|
2803
|
+
disabled: !name.trim() || create.pending,
|
|
2804
|
+
children: t(create.pending ? "common.working" : "common.add")
|
|
2805
|
+
})]
|
|
2806
|
+
})
|
|
2807
|
+
]
|
|
2808
|
+
})]
|
|
2809
|
+
})
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
var GENERAL_PURPOSE_ID = "general-purpose";
|
|
2813
|
+
/** A plugin tab's value, apart from the four fixed ids by its prefix. */
|
|
2814
|
+
function pluginTabValue(key) {
|
|
2815
|
+
return `plugin:${key}`;
|
|
2816
|
+
}
|
|
2817
|
+
/** Whether a person can pick this agent for a new session. It saves at once:
|
|
2818
|
+
* it is not part of the agent's definition draft and touches no running
|
|
2819
|
+
* session. The general-purpose agent is always on. */
|
|
2820
|
+
function DirectChatToggle({ agent, onChanged }) {
|
|
2821
|
+
const { t } = useTranslation();
|
|
2822
|
+
const toggle = useGatewayAction();
|
|
2823
|
+
const fixed = agent.agentId === GENERAL_PURPOSE_ID;
|
|
2824
|
+
const on = fixed || agent.startsSessions;
|
|
2825
|
+
const hint = fixed ? t("agents.startsSessionsAlways") : t(on ? "agents.directChatOn" : "agents.directChatOff");
|
|
2826
|
+
return /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
2827
|
+
/* @__PURE__ */ jsx(Failure, { reason: toggle.error }),
|
|
2828
|
+
/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
2829
|
+
"aria-label": `${t("agents.startsSessions")} ${agent.name}`,
|
|
2830
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
2831
|
+
variant: "ghost",
|
|
2832
|
+
size: "sm",
|
|
2833
|
+
type: "button",
|
|
2834
|
+
"aria-pressed": on,
|
|
2835
|
+
"aria-disabled": fixed || toggle.pending ? true : void 0,
|
|
2836
|
+
"data-slot": "agent-direct-chat",
|
|
2837
|
+
className: cn(on ? "text-success hover:text-success" : "text-muted-foreground"),
|
|
2838
|
+
onClick: (event) => {
|
|
2839
|
+
event.stopPropagation();
|
|
2840
|
+
if (fixed || toggle.pending) return;
|
|
2841
|
+
toggle.run((client) => client.call("config.agent.update", {
|
|
2842
|
+
agentId: agent.agentId,
|
|
2843
|
+
startsSessions: !on,
|
|
2844
|
+
expectedRevision: agent.revision,
|
|
2845
|
+
expectedContentHash: agent.contentHash
|
|
2846
|
+
})).then((done) => {
|
|
2847
|
+
if (done.ok) onChanged();
|
|
2848
|
+
});
|
|
2849
|
+
}
|
|
2850
|
+
}),
|
|
2851
|
+
children: on ? /* @__PURE__ */ jsx(MessageCircle, {
|
|
2852
|
+
"aria-hidden": "true",
|
|
2853
|
+
className: "size-4 shrink-0"
|
|
2854
|
+
}) : /* @__PURE__ */ jsx(MessageCircleOff, {
|
|
2855
|
+
"aria-hidden": "true",
|
|
2856
|
+
className: "size-4 shrink-0"
|
|
2857
|
+
})
|
|
2858
|
+
}),
|
|
2859
|
+
/* @__PURE__ */ jsx(TooltipContent, {
|
|
2860
|
+
side: "top",
|
|
2861
|
+
sideOffset: 6,
|
|
2862
|
+
children: hint
|
|
2863
|
+
})
|
|
2864
|
+
] });
|
|
2865
|
+
}
|
|
2866
|
+
/** Deletes one user-created agent after a confirmation that says what goes
|
|
2867
|
+
* with it. Absent on the general-purpose row, which cannot be removed. A
|
|
2868
|
+
* refusal stays in the dialog beside the button that asked. */
|
|
2869
|
+
function RemoveAgentButton({ agent, onRemoved }) {
|
|
2870
|
+
const { t } = useTranslation();
|
|
2871
|
+
const remove = useGatewayAction();
|
|
2872
|
+
const operationId = useRef(uuid());
|
|
2873
|
+
const [asking, setAsking] = useState(false);
|
|
2874
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
2875
|
+
"aria-label": `${t("agents.remove")} ${agent.name}`,
|
|
2876
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
2877
|
+
variant: "ghost",
|
|
2878
|
+
size: "sm",
|
|
2879
|
+
icon: "trash",
|
|
2880
|
+
type: "button",
|
|
2881
|
+
"data-slot": "agent-remove",
|
|
2882
|
+
onClick: (event) => {
|
|
2883
|
+
event.stopPropagation();
|
|
2884
|
+
setAsking(true);
|
|
2885
|
+
}
|
|
2886
|
+
})
|
|
2887
|
+
}), /* @__PURE__ */ jsx(TooltipContent, {
|
|
2888
|
+
side: "top",
|
|
2889
|
+
sideOffset: 6,
|
|
2890
|
+
children: t("agents.removeHint")
|
|
2891
|
+
})] }), /* @__PURE__ */ jsxs(AlertDialog, {
|
|
2892
|
+
open: asking,
|
|
2893
|
+
onOpenChange: (open) => {
|
|
2894
|
+
if (!open && !remove.pending) setAsking(false);
|
|
2895
|
+
},
|
|
2896
|
+
title: t("agents.removeTitle", { name: agent.name }),
|
|
2897
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
2898
|
+
variant: "ghost",
|
|
2899
|
+
disabled: remove.pending,
|
|
2900
|
+
onClick: () => setAsking(false),
|
|
2901
|
+
children: t("common.cancel")
|
|
2902
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2903
|
+
variant: "destructive",
|
|
2904
|
+
disabled: remove.pending,
|
|
2905
|
+
onClick: () => {
|
|
2906
|
+
remove.run(async (client) => {
|
|
2907
|
+
const result = await client.call("config.agent.remove", {
|
|
2908
|
+
operationId: operationId.current,
|
|
2909
|
+
agentIds: [agent.agentId]
|
|
2910
|
+
});
|
|
2911
|
+
if (result.operationState === "admitted") throw new Error(t("common.working"));
|
|
2912
|
+
return result;
|
|
2913
|
+
}).then((done) => {
|
|
2914
|
+
if (!done.ok) return;
|
|
2915
|
+
setAsking(false);
|
|
2916
|
+
onRemoved();
|
|
2917
|
+
});
|
|
2918
|
+
},
|
|
2919
|
+
children: t(remove.pending ? "common.working" : "agents.remove")
|
|
2920
|
+
})] }),
|
|
2921
|
+
children: [/* @__PURE__ */ jsx("p", { children: t("agents.removeBody", { id: agent.agentId }) }), /* @__PURE__ */ jsx(Failure, { reason: remove.error })]
|
|
2922
|
+
})] });
|
|
2923
|
+
}
|
|
2924
|
+
//#endregion
|
|
2925
|
+
//#region ui-src/index.tsx
|
|
2926
|
+
var runtimeVersion = 5;
|
|
2927
|
+
var provides = ["agent:identity"];
|
|
2928
|
+
function AgentSettings({ onLeaveGuard, ctx }) {
|
|
2929
|
+
const guards = useRef(/* @__PURE__ */ new Map());
|
|
2930
|
+
const register = useCallback((key, guard) => {
|
|
2931
|
+
if (guard) guards.current.set(key, guard);
|
|
2932
|
+
else guards.current.delete(key);
|
|
2933
|
+
onLeaveGuard?.(guards.current.size === 0 ? null : async () => {
|
|
2934
|
+
for (const leave of guards.current.values()) if (!await leave()) return false;
|
|
2935
|
+
return true;
|
|
2936
|
+
});
|
|
2937
|
+
}, [onLeaveGuard]);
|
|
2938
|
+
const pluginState = usePlugins((state) => state);
|
|
2939
|
+
const chapters = [...contributionsIn(pluginState, "shell.settings.category").filter((one) => one.contribution.parent === "agents")].sort((a, b) => (a.contribution.order ?? 100) - (b.contribution.order ?? 100) || a.sequence - b.sequence).map((one) => ({
|
|
2940
|
+
key: one.key,
|
|
2941
|
+
owner: one.plugin,
|
|
2942
|
+
label: resolveLabel(one.contribution.label, one.key),
|
|
2943
|
+
icon: one.contribution.icon,
|
|
2944
|
+
content: (register) => /* @__PURE__ */ jsx(SlotOutlet, {
|
|
2945
|
+
slot: "shell.settings.category",
|
|
2946
|
+
only: one.key,
|
|
2947
|
+
props: { onLeaveGuard: (guard) => register(one.key, guard) }
|
|
2948
|
+
})
|
|
2949
|
+
}));
|
|
2950
|
+
return /* @__PURE__ */ jsx(AgentsPanel, {
|
|
2951
|
+
register,
|
|
2952
|
+
chapters,
|
|
2953
|
+
ctx
|
|
2954
|
+
});
|
|
2955
|
+
}
|
|
2956
|
+
var register = (ctx) => {
|
|
2957
|
+
ctx.styles.add(styles_default, {
|
|
2958
|
+
layer: "unlayered",
|
|
2959
|
+
scope: "document"
|
|
2960
|
+
});
|
|
2961
|
+
ctx.i18n.contribute({
|
|
2962
|
+
"en-US": localeLeaves(catalogue$1),
|
|
2963
|
+
"zh-CN": localeLeaves(catalogue)
|
|
2964
|
+
}, "en-US");
|
|
2965
|
+
registerMetadata(ctx);
|
|
2966
|
+
ctx.services.provide("agent:identity", { component: (props) => /* @__PURE__ */ jsx(RenderingRegion, {
|
|
2967
|
+
owner: ctx.plugin,
|
|
2968
|
+
region: "agent:identity",
|
|
2969
|
+
children: /* @__PURE__ */ jsx(AgentAvatar, { ...props })
|
|
2970
|
+
}) });
|
|
2971
|
+
ctx.slots.register("shell.settings.category", {
|
|
2972
|
+
id: "agents",
|
|
2973
|
+
label: () => i18next.t("settings.agents"),
|
|
2974
|
+
icon: "bot",
|
|
2975
|
+
region: "preset",
|
|
2976
|
+
order: 35,
|
|
2977
|
+
layout: "fill",
|
|
2978
|
+
component: (props) => /* @__PURE__ */ jsx(AgentSettings, {
|
|
2979
|
+
...props,
|
|
2980
|
+
ctx
|
|
2981
|
+
})
|
|
2982
|
+
});
|
|
2983
|
+
};
|
|
2984
|
+
//#endregion
|
|
2985
|
+
export { provides, register, runtimeVersion };
|