@eum-agent/agent-management 0.0.0-stage → 1.0.0

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