@morlay/session-mode 0.0.0-stage → 0.2.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +85 -2
- package/dist/endpoint.d.mts +2 -0
- package/dist/endpoint.mjs +3 -0
- package/dist/index.d.mts +691 -0
- package/dist/index.mjs +2350 -0
- package/dist/mode-config-BIYT66jI.mjs +22 -0
- package/dist/mode-config-rules-z4gdHLR1.mjs +52 -0
- package/dist/rolldown-runtime-3qf6kE1h.d.mts +1 -0
- package/dist/server.d.mts +2 -0
- package/dist/server.mjs +1 -0
- package/dist/session-mode-endpoint-CLpvSnzM.d.mts +120 -0
- package/dist/session-mode-endpoint-Dq-E_kHt.mjs +53 -0
- package/dist/session-mode-endpoint.service-Bn4EH6aB.d.mts +21 -0
- package/dist/session-mode-endpoint.service-MrqQipN6.mjs +79 -0
- package/dist/testing.d.mts +12 -0
- package/dist/testing.mjs +23 -0
- package/dist/ui.d.mts +125 -0
- package/dist/ui.mjs +1165 -0
- package/package.json +63 -3
- package/src/context-assembler.provide.ts +139 -0
- package/src/context-assembler.service.ts +67 -0
- package/src/contract/context-assembler.contract.ts +30 -0
- package/src/contract/index.ts +3 -0
- package/src/contract/session-mode.contract.ts +104 -0
- package/src/contract/session-scope.contract.ts +53 -0
- package/src/defaults.ts +39 -0
- package/src/endpoint/index.ts +6 -0
- package/src/endpoint/mode-config-rules.ts +59 -0
- package/src/endpoint/mode-config.ts +58 -0
- package/src/endpoint/session-mode-endpoint.ts +121 -0
- package/src/endpoint/session-mode-shapes.ts +71 -0
- package/src/endpoint/tool-group-ref.ts +11 -0
- package/src/events.ts +102 -0
- package/src/guidance/groups.ts +101 -0
- package/src/guidance/index.ts +4 -0
- package/src/guidance/packs/ask.ts +17 -0
- package/src/guidance/packs/code.ts +25 -0
- package/src/guidance/packs/fs.ts +60 -0
- package/src/guidance/packs/index.ts +52 -0
- package/src/guidance/packs/mcp.ts +25 -0
- package/src/guidance/packs/plan.ts +42 -0
- package/src/guidance/packs/shell.ts +45 -0
- package/src/guidance/packs/skill.ts +12 -0
- package/src/guidance/packs/swarm.ts +60 -0
- package/src/guidance/packs/web-access.ts +24 -0
- package/src/guidance/tool-groups.ts +72 -0
- package/src/guidance/types.ts +29 -0
- package/src/index.ts +63 -0
- package/src/mode-sources.ts +83 -0
- package/src/mode-store.ts +45 -0
- package/src/modes.ts +126 -0
- package/src/per-agent-rows.ts +62 -0
- package/src/per-agent.ts +36 -0
- package/src/persona.ts +30 -0
- package/src/ptc-describe.ts +136 -0
- package/src/ptc-sdk.ts +101 -0
- package/src/reminder.ts +89 -0
- package/src/rules.ts +8 -0
- package/src/server/index.ts +7 -0
- package/src/server/session-mode-endpoint.service.ts +117 -0
- package/src/session-mode-store.ts +218 -0
- package/src/session-mode.projection.ts +78 -0
- package/src/session-mode.provide.ts +38 -0
- package/src/session-mode.service.ts +670 -0
- package/src/session-scope.service.ts +515 -0
- package/src/subagent/delegation-context.ts +30 -0
- package/src/subagent/return-guidance.ts +56 -0
- package/src/subagent/subagent-guidance.service.ts +76 -0
- package/src/subagent.provide.ts +5 -0
- package/src/system-remainder.ts +43 -0
- package/src/testing/index.ts +34 -0
- package/src/tool-guidance.service.ts +265 -0
- package/src/ui/index.ts +12 -0
- package/src/ui/locales.ts +134 -0
- package/src/ui/session-mode-endpoint.client.ts +19 -0
- package/src/ui/session-mode-locales.contribution.ts +51 -0
- package/src/ui/session-mode-panel-tab.ts +39 -0
- package/src/ui/session-mode-panel.view.tsx +931 -0
- package/src/ui/session-mode-seat.view.tsx +174 -0
- package/src/ui/session-mode-slots.ts +13 -0
- package/src/ui/session-mode.provide.ts +24 -0
- package/src/ui/session-mode.store.ts +90 -0
- package/src/ui/use-roster.ts +24 -0
- package/src/ui/view-props.ts +19 -0
package/dist/ui.mjs
ADDED
|
@@ -0,0 +1,1165 @@
|
|
|
1
|
+
import { Injectable, inject, provide } from "@morlay/zephyr";
|
|
2
|
+
import { Locale, RemoteTransport, SidebarRightTabs, SlotProvider, SlotView, SlotViewBase } from "@morlay/zephyr-app/client";
|
|
3
|
+
import { RemoteClient } from "@morlay/zephyr-app/remote";
|
|
4
|
+
import { n as __decorate, t as SessionModeEndpoint } from "./session-mode-endpoint-Dq-E_kHt.mjs";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { Button, IconAgentPresetOutlineRegular, IconChevronDownOutlineRegular, Menu, MenuItemButton, Modal, MultilineField, Row, SeatButton, SegmentedControl, Stack, Switch, Text } from "@morlay/zephyr-ui";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { i as groupRef, t as applyDraft } from "./mode-config-rules-z4gdHLR1.mjs";
|
|
9
|
+
// src/ui/session-mode-endpoint.client.ts
|
|
10
|
+
let SessionModeEndpointClient = class SessionModeEndpointClient extends SessionModeEndpoint {
|
|
11
|
+
/** 传输:转发走它(我们的组不注册进上游 `remote`)。 */
|
|
12
|
+
transport = inject(RemoteTransport);
|
|
13
|
+
};
|
|
14
|
+
SessionModeEndpointClient = __decorate([RemoteClient()], SessionModeEndpointClient);
|
|
15
|
+
// src/ui/session-mode.store.ts
|
|
16
|
+
let SessionModeStore = class SessionModeStore {
|
|
17
|
+
endpoint = inject(SessionModeEndpointClient);
|
|
18
|
+
roster;
|
|
19
|
+
actives = /* @__PURE__ */ new Map();
|
|
20
|
+
loadRoster() {
|
|
21
|
+
this.roster ??= this.endpoint.roster().catch((error) => {
|
|
22
|
+
this.roster = void 0;
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
25
|
+
return this.roster;
|
|
26
|
+
}
|
|
27
|
+
loadActive(sessionId) {
|
|
28
|
+
const pending = this.endpoint.active({ sessionId }).catch((error) => {
|
|
29
|
+
this.actives.delete(sessionId);
|
|
30
|
+
throw error;
|
|
31
|
+
});
|
|
32
|
+
this.actives.set(sessionId, pending);
|
|
33
|
+
return pending;
|
|
34
|
+
}
|
|
35
|
+
async select(sessionId, mode) {
|
|
36
|
+
const result = await this.endpoint.select({
|
|
37
|
+
sessionId,
|
|
38
|
+
mode
|
|
39
|
+
});
|
|
40
|
+
this.actives.delete(sessionId);
|
|
41
|
+
return result.mode;
|
|
42
|
+
}
|
|
43
|
+
async patch(sessionId, patch) {
|
|
44
|
+
return await this.cache(sessionId, this.endpoint.patch({
|
|
45
|
+
sessionId,
|
|
46
|
+
patch
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
async applyConfig(sessionId, config) {
|
|
50
|
+
return await this.cache(sessionId, this.endpoint.applyConfig({
|
|
51
|
+
sessionId,
|
|
52
|
+
config
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
async saveConfig(sessionId, config) {
|
|
56
|
+
const state = await this.cache(sessionId, this.endpoint.saveConfig({
|
|
57
|
+
sessionId,
|
|
58
|
+
config
|
|
59
|
+
}));
|
|
60
|
+
this.roster = void 0;
|
|
61
|
+
return state;
|
|
62
|
+
}
|
|
63
|
+
async saveAs(sessionId, code, name) {
|
|
64
|
+
const result = await this.endpoint.saveAs({
|
|
65
|
+
sessionId,
|
|
66
|
+
code,
|
|
67
|
+
...name === void 0 ? {} : { name }
|
|
68
|
+
});
|
|
69
|
+
this.roster = void 0;
|
|
70
|
+
return result.mode;
|
|
71
|
+
}
|
|
72
|
+
async remove(sessionId) {
|
|
73
|
+
const result = await this.endpoint.removeMode({ sessionId });
|
|
74
|
+
this.roster = void 0;
|
|
75
|
+
this.actives.delete(sessionId);
|
|
76
|
+
return result.mode;
|
|
77
|
+
}
|
|
78
|
+
async cache(sessionId, pending) {
|
|
79
|
+
const state = await pending;
|
|
80
|
+
this.actives.set(sessionId, Promise.resolve(state));
|
|
81
|
+
return state;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
SessionModeStore = __decorate([Injectable()], SessionModeStore);
|
|
85
|
+
// src/ui/session-mode-slots.ts
|
|
86
|
+
const PANEL_ID = "@morlay/session-mode";
|
|
87
|
+
let ConversationInputLeftSlot = class ConversationInputLeftSlot extends SlotViewBase {};
|
|
88
|
+
ConversationInputLeftSlot = __decorate([SlotProvider({
|
|
89
|
+
name: "conversation.input.left",
|
|
90
|
+
multi: true,
|
|
91
|
+
scope: "session"
|
|
92
|
+
})], ConversationInputLeftSlot);
|
|
93
|
+
let SidebarRightPaneTabSlot = class SidebarRightPaneTabSlot extends SlotViewBase {};
|
|
94
|
+
SidebarRightPaneTabSlot = __decorate([SlotProvider({
|
|
95
|
+
name: "sidebar.right.pane.tab",
|
|
96
|
+
multi: true,
|
|
97
|
+
scope: "session",
|
|
98
|
+
key: PANEL_ID
|
|
99
|
+
})], SidebarRightPaneTabSlot);
|
|
100
|
+
// src/ui/locales.ts
|
|
101
|
+
const zh = {
|
|
102
|
+
seatHint: "选择这个会话的模式",
|
|
103
|
+
lockedHint: "这个会话已经开始:换模式请新开一个会话",
|
|
104
|
+
seatFailed: "切换模式失败",
|
|
105
|
+
noDescription: "(无说明)",
|
|
106
|
+
panel: "会话模式",
|
|
107
|
+
panelDescription: "当前会话的模式与生效面:工具、技能、政策与注入开关。",
|
|
108
|
+
panelNoSession: "当前没有会话",
|
|
109
|
+
persona: "系统提示词",
|
|
110
|
+
tools: "工具",
|
|
111
|
+
skills: "技能",
|
|
112
|
+
policies: "政策规则",
|
|
113
|
+
switches: "注入面",
|
|
114
|
+
instructions: "工作区指令",
|
|
115
|
+
skillsCatalog: "技能目录",
|
|
116
|
+
runtimeContext: "动态快照",
|
|
117
|
+
empty: "(无)",
|
|
118
|
+
loading: "读取中…",
|
|
119
|
+
saveDefault: "保存为默认",
|
|
120
|
+
reset: "重置",
|
|
121
|
+
apply: "应用到会话",
|
|
122
|
+
applied: "已应用到会话",
|
|
123
|
+
fromSession: "会话覆盖",
|
|
124
|
+
fromMode: "模式默认",
|
|
125
|
+
saveAs: "另存为",
|
|
126
|
+
delete: "删除",
|
|
127
|
+
deleteConfirm: "删除这个模式在会话上的自定义?会话回到内置默认模式,原模式本身不受影响。",
|
|
128
|
+
cancel: "取消",
|
|
129
|
+
confirm: "确定",
|
|
130
|
+
nameLabel: "显示名(可选)",
|
|
131
|
+
codeLabel: "模式 code(必填)",
|
|
132
|
+
codePlaceholder: "例如 my-mode",
|
|
133
|
+
namePlaceholder: "新模式名",
|
|
134
|
+
general: "通用配置",
|
|
135
|
+
personaPrefix: "前缀",
|
|
136
|
+
personaSuffix: "后缀",
|
|
137
|
+
personaPrefixHint: "拼在系统提示词最前面的一段",
|
|
138
|
+
personaSuffixHint: "拼在系统提示词最后面的一段",
|
|
139
|
+
stateDefault: "默认",
|
|
140
|
+
stateOn: "开",
|
|
141
|
+
stateOff: "关",
|
|
142
|
+
stateAllow: "允许",
|
|
143
|
+
stateDeny: "禁止",
|
|
144
|
+
stateMixed: "混合",
|
|
145
|
+
otherGroup: "其它",
|
|
146
|
+
restoreDefault: "恢复默认",
|
|
147
|
+
onlyCallable: "只看可调用",
|
|
148
|
+
onlyCallableHint: "只列这个会话没被禁止、且当下可见的条目",
|
|
149
|
+
moreSaveWays: "更多保存方式",
|
|
150
|
+
saveAsNeedsName: "需要先给新模式起名(暂未提供输入面)",
|
|
151
|
+
deleteBuiltinReason: "内置模式不能删除,只有会话上自定义过的模式可删",
|
|
152
|
+
deleteCurrentTitle: "删除当前模式",
|
|
153
|
+
confirmDelete: "确认删除",
|
|
154
|
+
deleted: "已删除,会话回到",
|
|
155
|
+
deleteFailed: "删除失败",
|
|
156
|
+
savedNewMode: "已另存为新模式,对新会话生效",
|
|
157
|
+
saved: "已保存,对新会话生效",
|
|
158
|
+
saveFailed: "保存失败",
|
|
159
|
+
loadFailed: "读取失败"
|
|
160
|
+
};
|
|
161
|
+
const en = {
|
|
162
|
+
seatHint: "Pick the mode for this session",
|
|
163
|
+
lockedHint: "This session has started: start a new one to pick a mode",
|
|
164
|
+
seatFailed: "Mode switch failed",
|
|
165
|
+
noDescription: "(no description)",
|
|
166
|
+
panel: "Session mode",
|
|
167
|
+
panelDescription: "The mode this session runs and what it currently exposes: tools, skills, policies and injections.",
|
|
168
|
+
panelNoSession: "No session",
|
|
169
|
+
persona: "System prompt",
|
|
170
|
+
tools: "Tools",
|
|
171
|
+
skills: "Skills",
|
|
172
|
+
policies: "Policies",
|
|
173
|
+
switches: "Injections",
|
|
174
|
+
instructions: "Workspace instructions",
|
|
175
|
+
skillsCatalog: "Skill catalog",
|
|
176
|
+
runtimeContext: "Runtime context",
|
|
177
|
+
empty: "(none)",
|
|
178
|
+
loading: "Loading…",
|
|
179
|
+
saveDefault: "Save as default",
|
|
180
|
+
reset: "Reset",
|
|
181
|
+
apply: "Apply to session",
|
|
182
|
+
applied: "Applied to session",
|
|
183
|
+
fromSession: "session override",
|
|
184
|
+
fromMode: "mode default",
|
|
185
|
+
saveAs: "Save as",
|
|
186
|
+
delete: "Delete",
|
|
187
|
+
deleteConfirm: "Delete this session's customizations? The session falls back to the built-in default mode; the mode itself is untouched.",
|
|
188
|
+
cancel: "Cancel",
|
|
189
|
+
confirm: "Confirm",
|
|
190
|
+
nameLabel: "Display name (optional)",
|
|
191
|
+
codeLabel: "Mode code (required)",
|
|
192
|
+
codePlaceholder: "e.g. my-mode",
|
|
193
|
+
namePlaceholder: "New mode name",
|
|
194
|
+
general: "General",
|
|
195
|
+
personaPrefix: "Prefix",
|
|
196
|
+
personaSuffix: "Suffix",
|
|
197
|
+
personaPrefixHint: "Prepended to the system prompt",
|
|
198
|
+
personaSuffixHint: "Appended to the end of the system prompt",
|
|
199
|
+
stateDefault: "Default",
|
|
200
|
+
stateOn: "On",
|
|
201
|
+
stateOff: "Off",
|
|
202
|
+
stateAllow: "Allow",
|
|
203
|
+
stateDeny: "Deny",
|
|
204
|
+
stateMixed: "Mixed",
|
|
205
|
+
otherGroup: "Other",
|
|
206
|
+
restoreDefault: "Restore default",
|
|
207
|
+
onlyCallable: "Callable only",
|
|
208
|
+
onlyCallableHint: "List only what this session can actually call right now",
|
|
209
|
+
moreSaveWays: "More save options",
|
|
210
|
+
saveAsNeedsName: "A name for the new mode is required (no input surface yet)",
|
|
211
|
+
deleteBuiltinReason: "Built-in modes cannot be deleted; only modes customized on a session can",
|
|
212
|
+
deleteCurrentTitle: "Delete the current mode",
|
|
213
|
+
confirmDelete: "Confirm delete",
|
|
214
|
+
deleted: "Deleted; the session falls back to",
|
|
215
|
+
deleteFailed: "Delete failed",
|
|
216
|
+
savedNewMode: "Saved as a new mode; applies to new sessions",
|
|
217
|
+
saved: "Saved; applies to new sessions",
|
|
218
|
+
saveFailed: "Save failed",
|
|
219
|
+
loadFailed: "Load failed"
|
|
220
|
+
};
|
|
221
|
+
const LOCALE_NS = "session-mode";
|
|
222
|
+
// src/ui/session-mode-locales.contribution.ts
|
|
223
|
+
let SessionModeLocales = class SessionModeLocales {
|
|
224
|
+
locale = inject(Locale);
|
|
225
|
+
/**
|
|
226
|
+
* 字典的撤销面。归本行自己的 fiber:我们不 provide 字典,上游注册表才持有它。
|
|
227
|
+
*
|
|
228
|
+
* 自带字段而不是 `this.own(...)`:本行不是 `SlotContribution`(没有 slot 声明,也不该为拿 `own`
|
|
229
|
+
* 去多注入一个 `Slots`),基类的记账面拿不到——同一个理由,`onDispose` 也只能自己写。
|
|
230
|
+
*/
|
|
231
|
+
release;
|
|
232
|
+
onInit() {
|
|
233
|
+
this.release = this.locale.register(LOCALE_NS, {
|
|
234
|
+
zh,
|
|
235
|
+
en
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
onDispose() {
|
|
239
|
+
this.release?.();
|
|
240
|
+
this.release = void 0;
|
|
241
|
+
}
|
|
242
|
+
/** 本包字典绑定后的翻译座。 */
|
|
243
|
+
t() {
|
|
244
|
+
return this.locale.bind(LOCALE_NS);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
SessionModeLocales = __decorate([Injectable()], SessionModeLocales);
|
|
248
|
+
// src/ui/use-roster.ts
|
|
249
|
+
function useRoster(store) {
|
|
250
|
+
const [roster, setRoster] = useState(void 0);
|
|
251
|
+
useEffect(() => {
|
|
252
|
+
let alive = true;
|
|
253
|
+
store.loadRoster().then((value) => {
|
|
254
|
+
if (alive) setRoster(value);
|
|
255
|
+
}, () => {});
|
|
256
|
+
return () => {
|
|
257
|
+
alive = false;
|
|
258
|
+
};
|
|
259
|
+
}, [store]);
|
|
260
|
+
return roster;
|
|
261
|
+
}
|
|
262
|
+
// src/ui/view-props.ts
|
|
263
|
+
function viewPropsOf(value) {
|
|
264
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
265
|
+
}
|
|
266
|
+
// src/ui/session-mode-seat.view.tsx
|
|
267
|
+
const SEAT_STYLE = {
|
|
268
|
+
display: "flex",
|
|
269
|
+
flexDirection: "column",
|
|
270
|
+
gap: 4,
|
|
271
|
+
alignItems: "flex-start"
|
|
272
|
+
};
|
|
273
|
+
const fallbackTranslate$1 = (key) => zh[key];
|
|
274
|
+
const NO_SESSIONS$1 = () => void 0;
|
|
275
|
+
function projectionOf$1(snapshot, sessionId, key) {
|
|
276
|
+
return sessionId === void 0 ? void 0 : snapshot.byId[sessionId]?.projectionValues?.[key];
|
|
277
|
+
}
|
|
278
|
+
let SessionModeSeatView = class SessionModeSeatView extends ConversationInputLeftSlot {
|
|
279
|
+
store = inject(SessionModeStore);
|
|
280
|
+
locales = inject(SessionModeLocales);
|
|
281
|
+
render() {
|
|
282
|
+
const props = viewPropsOf(this.viewProps);
|
|
283
|
+
return /* @__PURE__ */ jsx(SessionModeSeat, {
|
|
284
|
+
sessionId: props.sessionId,
|
|
285
|
+
store: this.store,
|
|
286
|
+
useSessions: props.useSessions,
|
|
287
|
+
t: this.locales.t()
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
SessionModeSeatView = __decorate([SlotView()], SessionModeSeatView);
|
|
292
|
+
/** chip 的渲染本体(容器只负责注入,测试直接渲染它)。 */
|
|
293
|
+
function SessionModeSeat({ sessionId, store, useSessions, t = fallbackTranslate$1 }) {
|
|
294
|
+
const roster = useRoster(store);
|
|
295
|
+
const [open, setOpen] = useState(false);
|
|
296
|
+
const [busy, setBusy] = useState(false);
|
|
297
|
+
const [error, setError] = useState(null);
|
|
298
|
+
const sessions = useSessions ?? NO_SESSIONS$1;
|
|
299
|
+
const selected = sessions((snapshot) => projectionOf$1(snapshot, sessionId, "sessionMode"));
|
|
300
|
+
const editable = sessions((snapshot) => projectionOf$1(snapshot, sessionId, "sessionModeEditable"));
|
|
301
|
+
if (roster === void 0) return null;
|
|
302
|
+
const current = selected ?? roster.default;
|
|
303
|
+
const label = roster.modes.find((mode) => mode.id === current)?.name ?? current;
|
|
304
|
+
if (editable === false) return /* @__PURE__ */ jsx("div", {
|
|
305
|
+
"data-role": "session-mode-seat",
|
|
306
|
+
"data-locked": "true",
|
|
307
|
+
style: SEAT_STYLE,
|
|
308
|
+
children: /* @__PURE__ */ jsx(SeatButton, {
|
|
309
|
+
disabled: true,
|
|
310
|
+
title: t("lockedHint"),
|
|
311
|
+
icon: /* @__PURE__ */ jsx(IconAgentPresetOutlineRegular, {}),
|
|
312
|
+
label
|
|
313
|
+
})
|
|
314
|
+
});
|
|
315
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
316
|
+
"data-role": "session-mode-seat",
|
|
317
|
+
style: SEAT_STYLE,
|
|
318
|
+
children: [/* @__PURE__ */ jsx(Menu, {
|
|
319
|
+
open,
|
|
320
|
+
onClose: () => {
|
|
321
|
+
setOpen(false);
|
|
322
|
+
},
|
|
323
|
+
items: roster.modes.map((mode) => ({
|
|
324
|
+
id: mode.id,
|
|
325
|
+
label: /* @__PURE__ */ jsxs(Stack, {
|
|
326
|
+
gap: 2,
|
|
327
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
328
|
+
size: "md",
|
|
329
|
+
children: mode.name
|
|
330
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
331
|
+
size: "sm",
|
|
332
|
+
tone: "tertiary",
|
|
333
|
+
children: mode.description ?? t("noDescription")
|
|
334
|
+
})]
|
|
335
|
+
})
|
|
336
|
+
})),
|
|
337
|
+
selectedId: current,
|
|
338
|
+
onSelect: (id) => {
|
|
339
|
+
setOpen(false);
|
|
340
|
+
if (sessionId === void 0 || id === current) return;
|
|
341
|
+
setBusy(true);
|
|
342
|
+
setError(null);
|
|
343
|
+
store.select(sessionId, id).catch((cause) => {
|
|
344
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
345
|
+
}).finally(() => {
|
|
346
|
+
setBusy(false);
|
|
347
|
+
});
|
|
348
|
+
},
|
|
349
|
+
align: "start",
|
|
350
|
+
portal: true,
|
|
351
|
+
anchor: /* @__PURE__ */ jsx(SeatButton, {
|
|
352
|
+
"aria-haspopup": "menu",
|
|
353
|
+
"aria-expanded": open,
|
|
354
|
+
title: error ?? t("seatHint"),
|
|
355
|
+
disabled: busy,
|
|
356
|
+
icon: /* @__PURE__ */ jsx(IconAgentPresetOutlineRegular, {}),
|
|
357
|
+
label,
|
|
358
|
+
chevron: /* @__PURE__ */ jsx(IconChevronDownOutlineRegular, {}),
|
|
359
|
+
onClick: () => {
|
|
360
|
+
setOpen((value) => !value);
|
|
361
|
+
}
|
|
362
|
+
})
|
|
363
|
+
}), error === null ? null : /* @__PURE__ */ jsx("div", {
|
|
364
|
+
"data-role": "seat-error",
|
|
365
|
+
role: "alert",
|
|
366
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
367
|
+
as: "p",
|
|
368
|
+
size: "sm",
|
|
369
|
+
tone: "danger",
|
|
370
|
+
children: `${t("seatFailed")}: ${error}`
|
|
371
|
+
})
|
|
372
|
+
})]
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
// src/ui/session-mode-panel.view.tsx
|
|
376
|
+
const LIST_FIELDS = {
|
|
377
|
+
tools: {
|
|
378
|
+
allow: "allowTools",
|
|
379
|
+
deny: "denyTools"
|
|
380
|
+
},
|
|
381
|
+
skills: {
|
|
382
|
+
allow: "allowSkills",
|
|
383
|
+
deny: "denySkills"
|
|
384
|
+
},
|
|
385
|
+
policies: {
|
|
386
|
+
allow: "allowPolicies",
|
|
387
|
+
deny: "denyPolicies"
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
function messageOf(cause) {
|
|
391
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
392
|
+
}
|
|
393
|
+
const fallbackTranslate = (key) => zh[key];
|
|
394
|
+
const PANEL_STYLE = {
|
|
395
|
+
height: "100%",
|
|
396
|
+
overflowY: "auto",
|
|
397
|
+
boxSizing: "border-box",
|
|
398
|
+
padding: "20px 24px 40px"
|
|
399
|
+
};
|
|
400
|
+
const EMPTY_DRAFT = {
|
|
401
|
+
switches: {},
|
|
402
|
+
items: {
|
|
403
|
+
tools: {},
|
|
404
|
+
skills: {},
|
|
405
|
+
policies: {}
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
let SessionModePanelView = class SessionModePanelView extends SidebarRightPaneTabSlot {
|
|
409
|
+
store = inject(SessionModeStore);
|
|
410
|
+
locales = inject(SessionModeLocales);
|
|
411
|
+
render() {
|
|
412
|
+
const props = viewPropsOf(this.viewProps);
|
|
413
|
+
return /* @__PURE__ */ jsx(SessionModePanelBody, {
|
|
414
|
+
sessionId: props.sessionId,
|
|
415
|
+
store: this.store,
|
|
416
|
+
useSessions: props.useSessions,
|
|
417
|
+
panelId: PANEL_ID,
|
|
418
|
+
t: this.locales.t()
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
SessionModePanelView = __decorate([SlotView()], SessionModePanelView);
|
|
423
|
+
const NO_SESSIONS = () => void 0;
|
|
424
|
+
function projectionOf(snapshot, sessionId, key) {
|
|
425
|
+
return sessionId === void 0 ? void 0 : snapshot.byId[sessionId]?.projectionValues?.[key];
|
|
426
|
+
}
|
|
427
|
+
function SessionModePanelBody({ sessionId, store, useSessions, panelId, t = fallbackTranslate }) {
|
|
428
|
+
const [active, setActive] = useState(void 0);
|
|
429
|
+
const [errorOf, setErrorOf] = useState(void 0);
|
|
430
|
+
const [draft, setDraft] = useState(EMPTY_DRAFT);
|
|
431
|
+
const [notice, setNotice] = useState(null);
|
|
432
|
+
const [openSection, setOpenSection] = useState("general");
|
|
433
|
+
const [openGroups, setOpenGroups] = useState(/* @__PURE__ */ new Set());
|
|
434
|
+
const [onlyCallable, setOnlyCallable] = useState(false);
|
|
435
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
436
|
+
const [confirmingDelete, setConfirmingDelete] = useState(false);
|
|
437
|
+
const sessions = useSessions ?? NO_SESSIONS;
|
|
438
|
+
const sessionMode = sessions((snapshot) => projectionOf(snapshot, sessionId, "sessionMode"));
|
|
439
|
+
const agentPreset = sessions((snapshot) => projectionOf(snapshot, sessionId, "agentPreset"));
|
|
440
|
+
const loadedFor = useRef(void 0);
|
|
441
|
+
useEffect(() => {
|
|
442
|
+
if (sessionId === void 0) return;
|
|
443
|
+
let alive = true;
|
|
444
|
+
if (loadedFor.current !== sessionId) {
|
|
445
|
+
loadedFor.current = sessionId;
|
|
446
|
+
setActive(void 0);
|
|
447
|
+
setDraft(EMPTY_DRAFT);
|
|
448
|
+
}
|
|
449
|
+
store.loadActive(sessionId).then((value) => {
|
|
450
|
+
if (!alive) return;
|
|
451
|
+
setErrorOf(void 0);
|
|
452
|
+
setActive(value);
|
|
453
|
+
}, (cause) => {
|
|
454
|
+
if (alive) setErrorOf({
|
|
455
|
+
sessionId,
|
|
456
|
+
message: messageOf(cause)
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
return () => {
|
|
460
|
+
alive = false;
|
|
461
|
+
};
|
|
462
|
+
}, [
|
|
463
|
+
sessionId,
|
|
464
|
+
store,
|
|
465
|
+
sessionMode,
|
|
466
|
+
agentPreset
|
|
467
|
+
]);
|
|
468
|
+
if (sessionId === void 0) return /* @__PURE__ */ jsx("div", {
|
|
469
|
+
"data-role": "session-mode-panel",
|
|
470
|
+
"data-panel": panelId,
|
|
471
|
+
style: PANEL_STYLE,
|
|
472
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
473
|
+
size: "sm",
|
|
474
|
+
tone: "tertiary",
|
|
475
|
+
children: t("panelNoSession")
|
|
476
|
+
})
|
|
477
|
+
});
|
|
478
|
+
const error = errorOf?.sessionId === sessionId ? errorOf.message : void 0;
|
|
479
|
+
if (error !== void 0) return /* @__PURE__ */ jsx("div", {
|
|
480
|
+
"data-role": "session-mode-panel",
|
|
481
|
+
"data-panel": panelId,
|
|
482
|
+
style: PANEL_STYLE,
|
|
483
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
484
|
+
"data-role": "panel-error",
|
|
485
|
+
role: "alert",
|
|
486
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
487
|
+
as: "p",
|
|
488
|
+
size: "sm",
|
|
489
|
+
tone: "danger",
|
|
490
|
+
children: `${t("loadFailed")}: ${error}`
|
|
491
|
+
})
|
|
492
|
+
})
|
|
493
|
+
});
|
|
494
|
+
if (active === void 0) return /* @__PURE__ */ jsx("div", {
|
|
495
|
+
"data-role": "session-mode-panel",
|
|
496
|
+
"data-panel": panelId,
|
|
497
|
+
style: PANEL_STYLE,
|
|
498
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
499
|
+
size: "sm",
|
|
500
|
+
tone: "tertiary",
|
|
501
|
+
children: t("loading")
|
|
502
|
+
})
|
|
503
|
+
});
|
|
504
|
+
const effective = active.session === void 0 ? active.config : {
|
|
505
|
+
...active.config,
|
|
506
|
+
...active.session
|
|
507
|
+
};
|
|
508
|
+
const overridden = new Set(active.overriddenFields);
|
|
509
|
+
const source = (field) => overridden.has(field) ? t("fromSession") : t("fromMode");
|
|
510
|
+
const restore = (fields) => {
|
|
511
|
+
if (sessionId === void 0) return;
|
|
512
|
+
const patch = {};
|
|
513
|
+
for (const field of fields) patch[field] = null;
|
|
514
|
+
store.patch(sessionId, patch).then((value) => {
|
|
515
|
+
setActive(value);
|
|
516
|
+
setDraft((prev) => {
|
|
517
|
+
const switches = { ...prev.switches };
|
|
518
|
+
const items = {
|
|
519
|
+
tools: { ...prev.items.tools },
|
|
520
|
+
skills: { ...prev.items.skills },
|
|
521
|
+
policies: { ...prev.items.policies }
|
|
522
|
+
};
|
|
523
|
+
let persona = prev.persona;
|
|
524
|
+
for (const field of fields) {
|
|
525
|
+
delete switches[field];
|
|
526
|
+
if (field === "persona") persona = void 0;
|
|
527
|
+
for (const kind of [
|
|
528
|
+
"tools",
|
|
529
|
+
"skills",
|
|
530
|
+
"policies"
|
|
531
|
+
]) {
|
|
532
|
+
const pair = LIST_FIELDS[kind];
|
|
533
|
+
if (field === pair.allow || field === pair.deny) items[kind] = {};
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
switches,
|
|
538
|
+
items,
|
|
539
|
+
...persona === void 0 ? {} : { persona }
|
|
540
|
+
};
|
|
541
|
+
});
|
|
542
|
+
}).catch((cause) => {
|
|
543
|
+
setNotice(`${t("saveFailed")}: ${messageOf(cause)}`);
|
|
544
|
+
});
|
|
545
|
+
};
|
|
546
|
+
const draftOf = () => ({
|
|
547
|
+
lists: {
|
|
548
|
+
tools: draft.items.tools,
|
|
549
|
+
skills: draft.items.skills,
|
|
550
|
+
policies: draft.items.policies
|
|
551
|
+
},
|
|
552
|
+
...draft.persona === void 0 ? {} : { persona: { ...draft.persona } },
|
|
553
|
+
switches: draft.switches
|
|
554
|
+
});
|
|
555
|
+
const viewConfig = () => applyDraft(effective, draftOf(), active.config);
|
|
556
|
+
const commit = (target) => {
|
|
557
|
+
if (sessionId === void 0) return;
|
|
558
|
+
const config = viewConfig();
|
|
559
|
+
(target === "session" ? store.applyConfig(sessionId, config) : store.saveConfig(sessionId, config)).then((value) => {
|
|
560
|
+
setActive(value);
|
|
561
|
+
setDraft(EMPTY_DRAFT);
|
|
562
|
+
setNotice(t(target === "session" ? "applied" : "saved"));
|
|
563
|
+
}).catch((cause) => {
|
|
564
|
+
setNotice(`${t("saveFailed")}: ${messageOf(cause)}`);
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
const removeCurrent = () => {
|
|
568
|
+
if (sessionId === void 0) return;
|
|
569
|
+
setConfirmingDelete(false);
|
|
570
|
+
store.remove(sessionId).then(async (mode) => {
|
|
571
|
+
setNotice(`${t("deleted")} ${mode}`);
|
|
572
|
+
setActive(await store.loadActive(sessionId));
|
|
573
|
+
setDraft(EMPTY_DRAFT);
|
|
574
|
+
}).catch((cause) => {
|
|
575
|
+
setNotice(`${t("deleteFailed")}: ${messageOf(cause)}`);
|
|
576
|
+
});
|
|
577
|
+
};
|
|
578
|
+
const section = (key, title, children) => /* @__PURE__ */ jsx(Section, {
|
|
579
|
+
title,
|
|
580
|
+
open: openSection === key,
|
|
581
|
+
onToggle: () => {
|
|
582
|
+
setOpenSection((current) => current === key ? null : key);
|
|
583
|
+
},
|
|
584
|
+
children
|
|
585
|
+
});
|
|
586
|
+
const configValue = (entry) => {
|
|
587
|
+
if (entry.group !== void 0 && effective.denyTools.includes(groupRef(entry.group))) return "deny";
|
|
588
|
+
return entry.fallback === void 0 || entry.fallback === "default" ? "unset" : entry.fallback;
|
|
589
|
+
};
|
|
590
|
+
const entryOverridden = (entry) => entry.override !== void 0 && entry.override !== null;
|
|
591
|
+
const callable = (entry) => {
|
|
592
|
+
const groupDraft = entry.group === void 0 ? void 0 : draft.items.tools[groupRef(entry.group)];
|
|
593
|
+
if (groupDraft !== void 0) return groupDraft !== "deny";
|
|
594
|
+
return (draft.items.tools[entry.id] ?? entry.override ?? configValue(entry)) !== "deny";
|
|
595
|
+
};
|
|
596
|
+
const otherGroupLabel = t("otherGroup");
|
|
597
|
+
const toolGroups = /* @__PURE__ */ new Map();
|
|
598
|
+
for (const entry of active.catalog.tools) {
|
|
599
|
+
if (onlyCallable && !callable(entry)) continue;
|
|
600
|
+
const group = entry.group ?? otherGroupLabel;
|
|
601
|
+
const list = toolGroups.get(group);
|
|
602
|
+
if (list === void 0) toolGroups.set(group, [entry]);
|
|
603
|
+
else list.push(entry);
|
|
604
|
+
}
|
|
605
|
+
return /* @__PURE__ */ jsx("div", {
|
|
606
|
+
"data-role": "session-mode-panel",
|
|
607
|
+
"data-panel": panelId,
|
|
608
|
+
style: PANEL_STYLE,
|
|
609
|
+
children: /* @__PURE__ */ jsxs(Stack, {
|
|
610
|
+
gap: "wide",
|
|
611
|
+
children: [
|
|
612
|
+
/* @__PURE__ */ jsxs(Stack, {
|
|
613
|
+
gap: 4,
|
|
614
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
615
|
+
size: "lg",
|
|
616
|
+
children: active.mode.name
|
|
617
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
618
|
+
size: "sm",
|
|
619
|
+
tone: "tertiary",
|
|
620
|
+
children: active.mode.description.length === 0 ? t("noDescription") : active.mode.description
|
|
621
|
+
})]
|
|
622
|
+
}),
|
|
623
|
+
section("general", t("general"), /* @__PURE__ */ jsx(Stack, {
|
|
624
|
+
gap: 6,
|
|
625
|
+
children: [
|
|
626
|
+
[
|
|
627
|
+
"instructions",
|
|
628
|
+
"instructions",
|
|
629
|
+
effective.instructions
|
|
630
|
+
],
|
|
631
|
+
[
|
|
632
|
+
"skills",
|
|
633
|
+
"skillsCatalog",
|
|
634
|
+
effective.skills
|
|
635
|
+
],
|
|
636
|
+
[
|
|
637
|
+
"runtimeContext",
|
|
638
|
+
"runtimeContext",
|
|
639
|
+
effective.runtimeContext
|
|
640
|
+
]
|
|
641
|
+
].map(([key, labelKey, value]) => /* @__PURE__ */ jsxs(Row, {
|
|
642
|
+
gap: 6,
|
|
643
|
+
align: "center",
|
|
644
|
+
justify: "between",
|
|
645
|
+
children: [/* @__PURE__ */ jsxs(Stack, {
|
|
646
|
+
gap: 2,
|
|
647
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
648
|
+
size: "md",
|
|
649
|
+
children: t(labelKey)
|
|
650
|
+
}), /* @__PURE__ */ jsx(SourceLine, {
|
|
651
|
+
source: source(key),
|
|
652
|
+
restoreLabel: t("restoreDefault"),
|
|
653
|
+
onRestore: overridden.has(key) ? () => {
|
|
654
|
+
restore([key]);
|
|
655
|
+
} : void 0
|
|
656
|
+
})]
|
|
657
|
+
}), /* @__PURE__ */ jsx(Switch, {
|
|
658
|
+
checked: draft.switches[key] ?? value,
|
|
659
|
+
label: t(labelKey),
|
|
660
|
+
onChange: (next) => {
|
|
661
|
+
setDraft((prev) => ({
|
|
662
|
+
...prev,
|
|
663
|
+
switches: {
|
|
664
|
+
...prev.switches,
|
|
665
|
+
[key]: next
|
|
666
|
+
}
|
|
667
|
+
}));
|
|
668
|
+
}
|
|
669
|
+
})]
|
|
670
|
+
}, key))
|
|
671
|
+
})),
|
|
672
|
+
section("persona", t("persona"), /* @__PURE__ */ jsx(Stack, {
|
|
673
|
+
gap: 6,
|
|
674
|
+
children: [[
|
|
675
|
+
"prefix",
|
|
676
|
+
"personaPrefix",
|
|
677
|
+
"personaPrefixHint"
|
|
678
|
+
], [
|
|
679
|
+
"suffix",
|
|
680
|
+
"personaSuffix",
|
|
681
|
+
"personaSuffixHint"
|
|
682
|
+
]].map(([key, labelKey, hintKey]) => {
|
|
683
|
+
const value = draft.persona?.[key] ?? effective.persona[key];
|
|
684
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
685
|
+
gap: 2,
|
|
686
|
+
children: [
|
|
687
|
+
/* @__PURE__ */ jsx(Text, {
|
|
688
|
+
size: "md",
|
|
689
|
+
children: t(labelKey)
|
|
690
|
+
}),
|
|
691
|
+
/* @__PURE__ */ jsx(MultilineField, {
|
|
692
|
+
"aria-label": t(labelKey),
|
|
693
|
+
placeholder: t(hintKey),
|
|
694
|
+
value,
|
|
695
|
+
onChange: (event) => {
|
|
696
|
+
const next = event.currentTarget.value;
|
|
697
|
+
setDraft((prev) => ({
|
|
698
|
+
...prev,
|
|
699
|
+
persona: {
|
|
700
|
+
prefix: prev.persona?.prefix ?? effective.persona.prefix,
|
|
701
|
+
suffix: prev.persona?.suffix ?? effective.persona.suffix,
|
|
702
|
+
[key]: next
|
|
703
|
+
}
|
|
704
|
+
}));
|
|
705
|
+
}
|
|
706
|
+
}),
|
|
707
|
+
/* @__PURE__ */ jsx(SourceLine, {
|
|
708
|
+
source: source("persona"),
|
|
709
|
+
restoreLabel: t("restoreDefault"),
|
|
710
|
+
onRestore: overridden.has("persona") ? () => {
|
|
711
|
+
restore(["persona"]);
|
|
712
|
+
} : void 0
|
|
713
|
+
})
|
|
714
|
+
]
|
|
715
|
+
}, key);
|
|
716
|
+
})
|
|
717
|
+
})),
|
|
718
|
+
section("tools", `${t("tools")} (${String(active.catalog.tools.length)})`, /* @__PURE__ */ jsxs(Stack, {
|
|
719
|
+
gap: 2,
|
|
720
|
+
children: [
|
|
721
|
+
/* @__PURE__ */ jsxs(Row, {
|
|
722
|
+
gap: 6,
|
|
723
|
+
align: "center",
|
|
724
|
+
justify: "between",
|
|
725
|
+
children: [/* @__PURE__ */ jsxs(Stack, {
|
|
726
|
+
gap: 2,
|
|
727
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
728
|
+
size: "md",
|
|
729
|
+
children: t("onlyCallable")
|
|
730
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
731
|
+
size: "sm",
|
|
732
|
+
tone: "tertiary",
|
|
733
|
+
children: t("onlyCallableHint")
|
|
734
|
+
})]
|
|
735
|
+
}), /* @__PURE__ */ jsx(Switch, {
|
|
736
|
+
checked: onlyCallable,
|
|
737
|
+
label: t("onlyCallable"),
|
|
738
|
+
onChange: (next) => {
|
|
739
|
+
setOnlyCallable(next);
|
|
740
|
+
}
|
|
741
|
+
})]
|
|
742
|
+
}),
|
|
743
|
+
toolGroups.size === 0 && onlyCallable ? /* @__PURE__ */ jsx(Text, {
|
|
744
|
+
size: "sm",
|
|
745
|
+
tone: "tertiary",
|
|
746
|
+
children: t("empty")
|
|
747
|
+
}) : null,
|
|
748
|
+
[...toolGroups].map(([group, entries]) => {
|
|
749
|
+
const groupDraft = draft.items.tools[groupRef(group)];
|
|
750
|
+
const values = groupDraft !== void 0 ? entries.map(() => groupDraft) : entries.map((entry) => draft.items.tools[entry.id] ?? entry.override ?? configValue(entry));
|
|
751
|
+
const groupValue = values.every((value) => value === values[0]) ? values[0] ?? "unset" : "mixed";
|
|
752
|
+
const groupOverridden = entries.some((entry) => {
|
|
753
|
+
const fallback = entry.fallback === void 0 || entry.fallback === "default" ? "unset" : entry.fallback;
|
|
754
|
+
return (entry.override ?? configValue(entry)) !== fallback;
|
|
755
|
+
});
|
|
756
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
757
|
+
gap: 2,
|
|
758
|
+
children: [/* @__PURE__ */ jsx(TriStateRow, {
|
|
759
|
+
id: `${entries[0]?.groupLabel ?? group} (${String(entries.length)})`,
|
|
760
|
+
value: groupValue,
|
|
761
|
+
onChange: (next) => {
|
|
762
|
+
setDraft((prev) => ({
|
|
763
|
+
...prev,
|
|
764
|
+
items: {
|
|
765
|
+
...prev.items,
|
|
766
|
+
tools: {
|
|
767
|
+
...prev.items.tools,
|
|
768
|
+
[groupRef(group)]: next
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}));
|
|
772
|
+
},
|
|
773
|
+
onLabelClick: () => {
|
|
774
|
+
setOpenGroups((current) => {
|
|
775
|
+
const next = new Set(current);
|
|
776
|
+
if (next.has(group)) next.delete(group);
|
|
777
|
+
else next.add(group);
|
|
778
|
+
return next;
|
|
779
|
+
});
|
|
780
|
+
},
|
|
781
|
+
t,
|
|
782
|
+
source: groupOverridden ? t("fromSession") : t("fromMode"),
|
|
783
|
+
restoreLabel: t("restoreDefault"),
|
|
784
|
+
onRestore: groupOverridden ? () => {
|
|
785
|
+
restore([LIST_FIELDS.tools.allow, LIST_FIELDS.tools.deny]);
|
|
786
|
+
} : void 0
|
|
787
|
+
}), openGroups.has(group) ? entries.map((entry) => /* @__PURE__ */ jsx(TriStateRow, {
|
|
788
|
+
id: entry.id,
|
|
789
|
+
description: entry.description,
|
|
790
|
+
indent: 16,
|
|
791
|
+
value: draft.items.tools[entry.id] ?? entry.override ?? configValue(entry),
|
|
792
|
+
onChange: (next) => {
|
|
793
|
+
setDraft((prev) => ({
|
|
794
|
+
...prev,
|
|
795
|
+
items: {
|
|
796
|
+
...prev.items,
|
|
797
|
+
tools: {
|
|
798
|
+
...prev.items.tools,
|
|
799
|
+
[entry.id]: next
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}));
|
|
803
|
+
},
|
|
804
|
+
t,
|
|
805
|
+
source: entryOverridden(entry) ? t("fromSession") : t("fromMode"),
|
|
806
|
+
restoreLabel: t("restoreDefault"),
|
|
807
|
+
onRestore: entryOverridden(entry) ? () => {
|
|
808
|
+
restore([LIST_FIELDS.tools.allow, LIST_FIELDS.tools.deny]);
|
|
809
|
+
} : void 0
|
|
810
|
+
}, entry.id)) : null]
|
|
811
|
+
}, group);
|
|
812
|
+
})
|
|
813
|
+
]
|
|
814
|
+
})),
|
|
815
|
+
section("skills", `${t("skills")} (${String(active.catalog.skills.length)})`, /* @__PURE__ */ jsx(Stack, {
|
|
816
|
+
gap: 2,
|
|
817
|
+
children: active.catalog.skills.map((entry) => /* @__PURE__ */ jsx(TriStateRow, {
|
|
818
|
+
id: entry.id,
|
|
819
|
+
description: entry.description,
|
|
820
|
+
value: draft.items.skills[entry.id] ?? entry.override ?? configValue(entry),
|
|
821
|
+
onChange: (next) => {
|
|
822
|
+
setDraft((prev) => ({
|
|
823
|
+
...prev,
|
|
824
|
+
items: {
|
|
825
|
+
...prev.items,
|
|
826
|
+
skills: {
|
|
827
|
+
...prev.items.skills,
|
|
828
|
+
[entry.id]: next
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}));
|
|
832
|
+
},
|
|
833
|
+
t,
|
|
834
|
+
source: entryOverridden(entry) ? t("fromSession") : t("fromMode"),
|
|
835
|
+
restoreLabel: t("restoreDefault"),
|
|
836
|
+
onRestore: entryOverridden(entry) ? () => {
|
|
837
|
+
restore([LIST_FIELDS.skills.allow, LIST_FIELDS.skills.deny]);
|
|
838
|
+
} : void 0
|
|
839
|
+
}, entry.id))
|
|
840
|
+
})),
|
|
841
|
+
section("policies", `${t("policies")} (${String(active.catalog.policies.length)})`, /* @__PURE__ */ jsx(Stack, {
|
|
842
|
+
gap: 2,
|
|
843
|
+
children: active.catalog.policies.map((entry) => /* @__PURE__ */ jsx(TriStateRow, {
|
|
844
|
+
id: entry.id,
|
|
845
|
+
description: entry.description,
|
|
846
|
+
value: draft.items.policies[entry.id] ?? entry.override ?? configValue(entry),
|
|
847
|
+
onChange: (next) => {
|
|
848
|
+
setDraft((prev) => ({
|
|
849
|
+
...prev,
|
|
850
|
+
items: {
|
|
851
|
+
...prev.items,
|
|
852
|
+
policies: {
|
|
853
|
+
...prev.items.policies,
|
|
854
|
+
[entry.id]: next
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}));
|
|
858
|
+
},
|
|
859
|
+
t,
|
|
860
|
+
source: entryOverridden(entry) ? t("fromSession") : t("fromMode"),
|
|
861
|
+
restoreLabel: t("restoreDefault"),
|
|
862
|
+
onRestore: entryOverridden(entry) ? () => {
|
|
863
|
+
restore([LIST_FIELDS.policies.allow, LIST_FIELDS.policies.deny]);
|
|
864
|
+
} : void 0
|
|
865
|
+
}, entry.id))
|
|
866
|
+
})),
|
|
867
|
+
/* @__PURE__ */ jsxs(Row, {
|
|
868
|
+
gap: 8,
|
|
869
|
+
justify: "end",
|
|
870
|
+
align: "center",
|
|
871
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
872
|
+
variant: "outline",
|
|
873
|
+
onClick: () => {
|
|
874
|
+
setDraft(EMPTY_DRAFT);
|
|
875
|
+
setNotice(null);
|
|
876
|
+
},
|
|
877
|
+
children: t("reset")
|
|
878
|
+
}), /* @__PURE__ */ jsxs(Row, {
|
|
879
|
+
gap: 0,
|
|
880
|
+
align: "center",
|
|
881
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
882
|
+
variant: "primary",
|
|
883
|
+
style: {
|
|
884
|
+
borderTopRightRadius: 0,
|
|
885
|
+
borderBottomRightRadius: 0
|
|
886
|
+
},
|
|
887
|
+
onClick: () => {
|
|
888
|
+
commit("session");
|
|
889
|
+
},
|
|
890
|
+
children: t("apply")
|
|
891
|
+
}), /* @__PURE__ */ jsxs(Menu, {
|
|
892
|
+
open: menuOpen,
|
|
893
|
+
align: "end",
|
|
894
|
+
anchor: /* @__PURE__ */ jsx(Button, {
|
|
895
|
+
variant: "primary",
|
|
896
|
+
"aria-label": t("moreSaveWays"),
|
|
897
|
+
style: {
|
|
898
|
+
borderTopLeftRadius: 0,
|
|
899
|
+
borderBottomLeftRadius: 0,
|
|
900
|
+
paddingInline: 6
|
|
901
|
+
},
|
|
902
|
+
onClick: () => {
|
|
903
|
+
setMenuOpen(true);
|
|
904
|
+
},
|
|
905
|
+
children: /* @__PURE__ */ jsx(IconChevronDownOutlineRegular, {})
|
|
906
|
+
}),
|
|
907
|
+
onClose: () => {
|
|
908
|
+
setMenuOpen(false);
|
|
909
|
+
},
|
|
910
|
+
children: [
|
|
911
|
+
/* @__PURE__ */ jsx(MenuItemButton, {
|
|
912
|
+
onSelect: () => {
|
|
913
|
+
setMenuOpen(false);
|
|
914
|
+
commit("config");
|
|
915
|
+
},
|
|
916
|
+
children: t("saveDefault")
|
|
917
|
+
}),
|
|
918
|
+
/* @__PURE__ */ jsx(MenuItemButton, {
|
|
919
|
+
disabled: true,
|
|
920
|
+
disabledReason: t("saveAsNeedsName"),
|
|
921
|
+
onSelect: () => {},
|
|
922
|
+
children: t("saveAs")
|
|
923
|
+
}),
|
|
924
|
+
/* @__PURE__ */ jsx(MenuItemButton, {
|
|
925
|
+
disabled: !active.deletable,
|
|
926
|
+
...active.deletable ? {} : { disabledReason: t("deleteBuiltinReason") },
|
|
927
|
+
danger: true,
|
|
928
|
+
onSelect: () => {
|
|
929
|
+
setMenuOpen(false);
|
|
930
|
+
setConfirmingDelete(true);
|
|
931
|
+
},
|
|
932
|
+
children: t("delete")
|
|
933
|
+
})
|
|
934
|
+
]
|
|
935
|
+
})]
|
|
936
|
+
})]
|
|
937
|
+
}),
|
|
938
|
+
!confirmingDelete ? null : /* @__PURE__ */ jsx(Modal, {
|
|
939
|
+
open: true,
|
|
940
|
+
onClose: () => {
|
|
941
|
+
setConfirmingDelete(false);
|
|
942
|
+
},
|
|
943
|
+
title: t("deleteCurrentTitle"),
|
|
944
|
+
closeLabel: t("cancel"),
|
|
945
|
+
description: `「${active.mode.name}」${t("deleteConfirm")}`,
|
|
946
|
+
footer: /* @__PURE__ */ jsxs(Row, {
|
|
947
|
+
gap: 8,
|
|
948
|
+
justify: "end",
|
|
949
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
950
|
+
variant: "outline",
|
|
951
|
+
onClick: () => {
|
|
952
|
+
setConfirmingDelete(false);
|
|
953
|
+
},
|
|
954
|
+
children: t("cancel")
|
|
955
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
956
|
+
variant: "primary",
|
|
957
|
+
tone: "danger",
|
|
958
|
+
onClick: removeCurrent,
|
|
959
|
+
children: t("confirmDelete")
|
|
960
|
+
})]
|
|
961
|
+
})
|
|
962
|
+
}),
|
|
963
|
+
notice === null ? null : /* @__PURE__ */ jsx(Text, {
|
|
964
|
+
as: "p",
|
|
965
|
+
size: "sm",
|
|
966
|
+
tone: "tertiary",
|
|
967
|
+
children: notice
|
|
968
|
+
})
|
|
969
|
+
]
|
|
970
|
+
})
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
function Section({ title, open, onToggle, children }) {
|
|
974
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
975
|
+
"data-role": "section",
|
|
976
|
+
"data-section": title,
|
|
977
|
+
style: { borderTop: "1px solid var(--dsw-alias-border-l1)" },
|
|
978
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
979
|
+
type: "button",
|
|
980
|
+
"data-role": "section-heading",
|
|
981
|
+
onClick: onToggle,
|
|
982
|
+
style: {
|
|
983
|
+
width: "100%",
|
|
984
|
+
display: "flex",
|
|
985
|
+
alignItems: "center",
|
|
986
|
+
justifyContent: "space-between",
|
|
987
|
+
background: "none",
|
|
988
|
+
border: 0,
|
|
989
|
+
paddingBlock: 12,
|
|
990
|
+
paddingInline: 0,
|
|
991
|
+
font: "inherit",
|
|
992
|
+
fontSize: 13,
|
|
993
|
+
fontWeight: 500,
|
|
994
|
+
color: "inherit",
|
|
995
|
+
cursor: "pointer"
|
|
996
|
+
},
|
|
997
|
+
children: [/* @__PURE__ */ jsx("span", { children: title }), /* @__PURE__ */ jsx("span", {
|
|
998
|
+
"data-role": "section-icon",
|
|
999
|
+
style: { color: "var(--dsw-alias-label-tertiary)" },
|
|
1000
|
+
children: open ? "−" : "+"
|
|
1001
|
+
})]
|
|
1002
|
+
}), open ? /* @__PURE__ */ jsx("div", {
|
|
1003
|
+
style: { padding: "0 0 8px" },
|
|
1004
|
+
children: /* @__PURE__ */ jsx(Stack, {
|
|
1005
|
+
gap: 6,
|
|
1006
|
+
children
|
|
1007
|
+
})
|
|
1008
|
+
}) : null]
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
function SourceLine({ source, restoreLabel, onRestore }) {
|
|
1012
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
1013
|
+
style: {
|
|
1014
|
+
display: "flex",
|
|
1015
|
+
alignItems: "center",
|
|
1016
|
+
gap: 6
|
|
1017
|
+
},
|
|
1018
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
1019
|
+
size: "sm",
|
|
1020
|
+
tone: "tertiary",
|
|
1021
|
+
children: source
|
|
1022
|
+
}), onRestore === void 0 ? null : /* @__PURE__ */ jsx("button", {
|
|
1023
|
+
type: "button",
|
|
1024
|
+
onClick: () => {
|
|
1025
|
+
onRestore();
|
|
1026
|
+
},
|
|
1027
|
+
style: {
|
|
1028
|
+
background: "none",
|
|
1029
|
+
border: 0,
|
|
1030
|
+
padding: 0,
|
|
1031
|
+
font: "inherit",
|
|
1032
|
+
fontSize: 12,
|
|
1033
|
+
color: "var(--dsw-alias-label-secondary)",
|
|
1034
|
+
textDecoration: "underline",
|
|
1035
|
+
cursor: "pointer"
|
|
1036
|
+
},
|
|
1037
|
+
children: restoreLabel
|
|
1038
|
+
})]
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
function TriStateRow({ id, description, value, indent = 0, onChange, onLabelClick, source, restoreLabel, onRestore, t }) {
|
|
1042
|
+
const translate = t ?? fallbackTranslate;
|
|
1043
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1044
|
+
"data-role": "tri-state",
|
|
1045
|
+
"data-id": id,
|
|
1046
|
+
style: {
|
|
1047
|
+
display: "flex",
|
|
1048
|
+
flexWrap: "wrap",
|
|
1049
|
+
alignItems: "center",
|
|
1050
|
+
justifyContent: "space-between",
|
|
1051
|
+
gap: 8,
|
|
1052
|
+
padding: "6px 0",
|
|
1053
|
+
paddingLeft: indent
|
|
1054
|
+
},
|
|
1055
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1056
|
+
style: {
|
|
1057
|
+
display: "flex",
|
|
1058
|
+
flexDirection: "column",
|
|
1059
|
+
gap: 2,
|
|
1060
|
+
minWidth: 0,
|
|
1061
|
+
flex: "1 1 140px"
|
|
1062
|
+
},
|
|
1063
|
+
children: [
|
|
1064
|
+
onLabelClick === void 0 ? /* @__PURE__ */ jsx(Text, {
|
|
1065
|
+
size: "sm",
|
|
1066
|
+
children: id
|
|
1067
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
1068
|
+
type: "button",
|
|
1069
|
+
onClick: onLabelClick,
|
|
1070
|
+
style: {
|
|
1071
|
+
background: "none",
|
|
1072
|
+
border: 0,
|
|
1073
|
+
padding: 0,
|
|
1074
|
+
font: "inherit",
|
|
1075
|
+
fontSize: 13,
|
|
1076
|
+
color: "inherit",
|
|
1077
|
+
textAlign: "left",
|
|
1078
|
+
cursor: "pointer"
|
|
1079
|
+
},
|
|
1080
|
+
children: id
|
|
1081
|
+
}),
|
|
1082
|
+
description === void 0 || description.length === 0 ? null : /* @__PURE__ */ jsx(Text, {
|
|
1083
|
+
size: "sm",
|
|
1084
|
+
tone: "tertiary",
|
|
1085
|
+
children: description
|
|
1086
|
+
}),
|
|
1087
|
+
source === void 0 ? null : /* @__PURE__ */ jsx(SourceLine, {
|
|
1088
|
+
source,
|
|
1089
|
+
restoreLabel,
|
|
1090
|
+
onRestore
|
|
1091
|
+
})
|
|
1092
|
+
]
|
|
1093
|
+
}), /* @__PURE__ */ jsx(SegmentedControl, {
|
|
1094
|
+
id: `tri-${id.replace(/[^a-zA-Z0-9_-]+/gu, "-")}`,
|
|
1095
|
+
label: id,
|
|
1096
|
+
value,
|
|
1097
|
+
options: value === "mixed" ? [
|
|
1098
|
+
{
|
|
1099
|
+
value: "mixed",
|
|
1100
|
+
label: translate("stateMixed")
|
|
1101
|
+
},
|
|
1102
|
+
{
|
|
1103
|
+
value: "unset",
|
|
1104
|
+
label: translate("stateDefault")
|
|
1105
|
+
},
|
|
1106
|
+
{
|
|
1107
|
+
value: "allow",
|
|
1108
|
+
label: translate("stateAllow")
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
value: "deny",
|
|
1112
|
+
label: translate("stateDeny")
|
|
1113
|
+
}
|
|
1114
|
+
] : [
|
|
1115
|
+
{
|
|
1116
|
+
value: "unset",
|
|
1117
|
+
label: translate("stateDefault")
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
value: "allow",
|
|
1121
|
+
label: translate("stateAllow")
|
|
1122
|
+
},
|
|
1123
|
+
{
|
|
1124
|
+
value: "deny",
|
|
1125
|
+
label: translate("stateDeny")
|
|
1126
|
+
}
|
|
1127
|
+
],
|
|
1128
|
+
onChange: (next) => {
|
|
1129
|
+
if (next === "mixed") return;
|
|
1130
|
+
onChange(next);
|
|
1131
|
+
}
|
|
1132
|
+
})]
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
// src/ui/session-mode-panel-tab.ts
|
|
1136
|
+
let SessionModePanelTab = class SessionModePanelTab {
|
|
1137
|
+
tabs = inject(SidebarRightTabs);
|
|
1138
|
+
locales = inject(SessionModeLocales);
|
|
1139
|
+
onInit() {
|
|
1140
|
+
const t = this.locales.t();
|
|
1141
|
+
this.tabs.register({
|
|
1142
|
+
id: PANEL_ID,
|
|
1143
|
+
kind: PANEL_ID,
|
|
1144
|
+
priority: "extension",
|
|
1145
|
+
title: () => t("panel"),
|
|
1146
|
+
guide: [{
|
|
1147
|
+
id: "panel",
|
|
1148
|
+
order: 40,
|
|
1149
|
+
title: () => t("panel"),
|
|
1150
|
+
description: () => t("panelDescription")
|
|
1151
|
+
}]
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
};
|
|
1155
|
+
SessionModePanelTab = __decorate([Injectable()], SessionModePanelTab);
|
|
1156
|
+
// src/ui/session-mode.provide.ts
|
|
1157
|
+
const provideSessionModeUi = provide([
|
|
1158
|
+
SessionModeEndpointClient,
|
|
1159
|
+
SessionModeStore,
|
|
1160
|
+
SessionModeLocales,
|
|
1161
|
+
SessionModePanelTab,
|
|
1162
|
+
SessionModeSeatView,
|
|
1163
|
+
SessionModePanelView
|
|
1164
|
+
]);
|
|
1165
|
+
export { ConversationInputLeftSlot, LOCALE_NS, PANEL_ID, SessionModeEndpointClient, SessionModePanelView, SessionModeSeatView, SessionModeStore, SidebarRightPaneTabSlot, en, provideSessionModeUi, zh };
|