@truefoundry/trueforge-ui 0.3.0-rc.0 → 0.3.0-rc.10

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 (115) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/README.md +35 -12
  3. package/dist/AgentCodeSnippets-RJBB4DDE.js +89 -0
  4. package/dist/AgentCodeSnippets-RJBB4DDE.js.map +1 -0
  5. package/dist/AgentMetricChart-UPGSJ2WP.js +15 -0
  6. package/dist/AgentOverview-U5WIQXZN.js +169 -0
  7. package/dist/AgentOverview-U5WIQXZN.js.map +1 -0
  8. package/dist/AgentSessionEventTimeline-GRGIQTRE.js +88 -0
  9. package/dist/AgentSessionEventTimeline-GRGIQTRE.js.map +1 -0
  10. package/dist/AgentSessionEventTimelineChart-GNF4VOUT.js +591 -0
  11. package/dist/AgentSessionEventTimelineChart-GNF4VOUT.js.map +1 -0
  12. package/dist/AgentSessions-5OTF2BUW.js +323 -0
  13. package/dist/AgentSessions-5OTF2BUW.js.map +1 -0
  14. package/dist/{ConnectorSettings-FXQ5B7TN.js → ConnectorSettings-HDKGLDCY.js} +163 -125
  15. package/dist/ConnectorSettings-HDKGLDCY.js.map +1 -0
  16. package/dist/{DockLayout-LBNQJZNF.js → DockLayout-D2FPQCAL.js} +11 -10
  17. package/dist/{DockLayout-LBNQJZNF.js.map → DockLayout-D2FPQCAL.js.map} +1 -1
  18. package/dist/DrawerLayout-HUV7RAWL.js +186 -0
  19. package/dist/DrawerLayout-HUV7RAWL.js.map +1 -0
  20. package/dist/{ModelSettings-4L4LOQJA.js → ModelSettings-VNQ7HPKH.js} +23 -27
  21. package/dist/ModelSettings-VNQ7HPKH.js.map +1 -0
  22. package/dist/OpenUiFenceBlock-KPZFLUSC.js +9 -0
  23. package/dist/OpenUiFenceBlock-KPZFLUSC.js.map +1 -0
  24. package/dist/{SandboxSettings-Z4ZG6ZX4.js → SandboxSettings-ZLXGMFBF.js} +18 -20
  25. package/dist/SandboxSettings-ZLXGMFBF.js.map +1 -0
  26. package/dist/SchedulesPage-QKYI2Z3A.js +15 -0
  27. package/dist/SchedulesPage-QKYI2Z3A.js.map +1 -0
  28. package/dist/{SettingsBuilder-WF7ZWKQW.js → SettingsBuilder-RVVYXOJW.js} +27 -23
  29. package/dist/SettingsBuilder-RVVYXOJW.js.map +1 -0
  30. package/dist/ShellRouteSync-SJXFKUAJ.js +390 -0
  31. package/dist/ShellRouteSync-SJXFKUAJ.js.map +1 -0
  32. package/dist/SidebarLayout-KYA76FQ7.js +330 -0
  33. package/dist/SidebarLayout-KYA76FQ7.js.map +1 -0
  34. package/dist/{SkillSettings-3EPPC3IT.js → SkillSettings-7OHT7FPI.js} +25 -21
  35. package/dist/SkillSettings-7OHT7FPI.js.map +1 -0
  36. package/dist/{TrueForgeUIWithRouter-NZ4FGPE4.js → TrueForgeUIWithRouter-LKG4XLW6.js} +14 -10
  37. package/dist/{TrueForgeUIWithRouter-NZ4FGPE4.js.map → TrueForgeUIWithRouter-LKG4XLW6.js.map} +1 -1
  38. package/dist/{WidgetLayout-3QZ357FL.js → WidgetLayout-W2RGGOQ3.js} +17 -13
  39. package/dist/WidgetLayout-W2RGGOQ3.js.map +1 -0
  40. package/dist/chunk-2GIZY3JJ.js +1062 -0
  41. package/dist/chunk-2GIZY3JJ.js.map +1 -0
  42. package/dist/chunk-2QTH6JHX.js +217 -0
  43. package/dist/chunk-2QTH6JHX.js.map +1 -0
  44. package/dist/{chunk-FJ5RSSMA.js → chunk-3ZW74FHC.js} +118 -164
  45. package/dist/chunk-3ZW74FHC.js.map +1 -0
  46. package/dist/chunk-67ZO7Z2W.js +184 -0
  47. package/dist/chunk-67ZO7Z2W.js.map +1 -0
  48. package/dist/{chunk-CFLVPV5M.js → chunk-7AAO4UDQ.js} +8 -2
  49. package/dist/chunk-7AAO4UDQ.js.map +1 -0
  50. package/dist/{chunk-B52K63AW.js → chunk-CG75X77Q.js} +2 -2
  51. package/dist/chunk-DJUFS2BW.js +27 -0
  52. package/dist/chunk-DJUFS2BW.js.map +1 -0
  53. package/dist/chunk-DPPOEFBD.js +517 -0
  54. package/dist/chunk-DPPOEFBD.js.map +1 -0
  55. package/dist/chunk-EPAL2HD5.js +1629 -0
  56. package/dist/chunk-EPAL2HD5.js.map +1 -0
  57. package/dist/chunk-GG23N2GW.js +15018 -0
  58. package/dist/chunk-GG23N2GW.js.map +1 -0
  59. package/dist/chunk-JCL3Q7RW.js +587 -0
  60. package/dist/chunk-JCL3Q7RW.js.map +1 -0
  61. package/dist/chunk-JKEBMGLH.js +682 -0
  62. package/dist/chunk-JKEBMGLH.js.map +1 -0
  63. package/dist/chunk-KSGNKS2D.js +296 -0
  64. package/dist/chunk-KSGNKS2D.js.map +1 -0
  65. package/dist/{chunk-WREC7D54.js → chunk-PCI6VMB5.js} +268 -48
  66. package/dist/chunk-PCI6VMB5.js.map +1 -0
  67. package/dist/chunk-PQ7VWBQQ.js +121 -0
  68. package/dist/chunk-PQ7VWBQQ.js.map +1 -0
  69. package/dist/chunk-RDXBMTP5.js +32 -0
  70. package/dist/chunk-RDXBMTP5.js.map +1 -0
  71. package/dist/chunk-T6QQV5LK.js +238 -0
  72. package/dist/chunk-T6QQV5LK.js.map +1 -0
  73. package/dist/chunk-Y6S4OVVQ.js +16 -0
  74. package/dist/chunk-Y6S4OVVQ.js.map +1 -0
  75. package/dist/{createTrueFoundryServer-B72bU-J7.d.ts → createTrueFoundryServer-B_FYhSdn.d.ts} +18 -4
  76. package/dist/index.d.ts +1287 -46
  77. package/dist/index.js +266 -63
  78. package/dist/index.js.map +1 -1
  79. package/dist/plugins/trueforge-agent-server-adapter/index.d.ts +590 -11
  80. package/dist/plugins/trueforge-agent-server-adapter/index.js +607 -204
  81. package/dist/plugins/trueforge-agent-server-adapter/index.js.map +1 -1
  82. package/dist/styles.css +1 -1
  83. package/package.json +10 -8
  84. package/dist/ConnectorSettings-FXQ5B7TN.js.map +0 -1
  85. package/dist/DrawerLayout-Q6UK4VMI.js +0 -159
  86. package/dist/DrawerLayout-Q6UK4VMI.js.map +0 -1
  87. package/dist/ModelSettings-4L4LOQJA.js.map +0 -1
  88. package/dist/OpenUiFenceBlock-6UIIAVBX.js +0 -9
  89. package/dist/SandboxSettings-Z4ZG6ZX4.js.map +0 -1
  90. package/dist/SettingsBuilder-WF7ZWKQW.js.map +0 -1
  91. package/dist/ShellRouteSync-T4WLY57Q.js +0 -172
  92. package/dist/ShellRouteSync-T4WLY57Q.js.map +0 -1
  93. package/dist/SidebarLayout-3WZ3CVON.js +0 -256
  94. package/dist/SidebarLayout-3WZ3CVON.js.map +0 -1
  95. package/dist/SkillSettings-3EPPC3IT.js.map +0 -1
  96. package/dist/WidgetLayout-3QZ357FL.js.map +0 -1
  97. package/dist/chunk-36KOSC2J.js +0 -567
  98. package/dist/chunk-36KOSC2J.js.map +0 -1
  99. package/dist/chunk-3S6KHO7H.js +0 -2121
  100. package/dist/chunk-3S6KHO7H.js.map +0 -1
  101. package/dist/chunk-7L63OK3O.js +0 -91
  102. package/dist/chunk-7L63OK3O.js.map +0 -1
  103. package/dist/chunk-CFLVPV5M.js.map +0 -1
  104. package/dist/chunk-FJ5RSSMA.js.map +0 -1
  105. package/dist/chunk-OSV3HI5M.js +0 -6891
  106. package/dist/chunk-OSV3HI5M.js.map +0 -1
  107. package/dist/chunk-WQULF5AT.js +0 -460
  108. package/dist/chunk-WQULF5AT.js.map +0 -1
  109. package/dist/chunk-WREC7D54.js.map +0 -1
  110. package/dist/chunk-YIWUG6MC.js +0 -101
  111. package/dist/chunk-YIWUG6MC.js.map +0 -1
  112. package/dist/chunk-ZXOADNF3.js +0 -75
  113. package/dist/chunk-ZXOADNF3.js.map +0 -1
  114. /package/dist/{OpenUiFenceBlock-6UIIAVBX.js.map → AgentMetricChart-UPGSJ2WP.js.map} +0 -0
  115. /package/dist/{chunk-B52K63AW.js.map → chunk-CG75X77Q.js.map} +0 -0
@@ -0,0 +1,1062 @@
1
+ // src/server/ServerContext.tsx
2
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var ServerContext = createContext(null);
5
+ var ServerCapabilitiesContext = createContext(null);
6
+ function ServerProvider({ server, children }) {
7
+ const [capabilities, setCapabilities] = useState(null);
8
+ const [capabilitiesSettled, setCapabilitiesSettled] = useState(false);
9
+ const cancelActiveRequestRef = useRef(null);
10
+ const refreshCapabilities = useCallback(() => {
11
+ cancelActiveRequestRef.current?.();
12
+ let cancelled = false;
13
+ cancelActiveRequestRef.current = () => {
14
+ cancelled = true;
15
+ };
16
+ void server.getCapabilities().then((response) => {
17
+ if (!cancelled) setCapabilities(response.data);
18
+ }).catch(() => {
19
+ }).finally(() => {
20
+ if (!cancelled) setCapabilitiesSettled(true);
21
+ });
22
+ }, [server]);
23
+ useEffect(() => {
24
+ setCapabilities(null);
25
+ setCapabilitiesSettled(false);
26
+ refreshCapabilities();
27
+ return () => {
28
+ cancelActiveRequestRef.current?.();
29
+ };
30
+ }, [refreshCapabilities]);
31
+ const capabilitiesValue = useMemo(
32
+ () => ({ capabilities, settled: capabilitiesSettled, refresh: refreshCapabilities }),
33
+ [capabilities, capabilitiesSettled, refreshCapabilities]
34
+ );
35
+ return /* @__PURE__ */ jsx(ServerContext.Provider, { value: server, children: /* @__PURE__ */ jsx(ServerCapabilitiesContext.Provider, { value: capabilitiesValue, children }) });
36
+ }
37
+ function useServer() {
38
+ const server = useContext(ServerContext);
39
+ if (server == null) {
40
+ throw new Error("useServer must be used within a ServerProvider.");
41
+ }
42
+ return server;
43
+ }
44
+ function useOptionalServer() {
45
+ return useContext(ServerContext);
46
+ }
47
+ function useServerCapabilities() {
48
+ return useContext(ServerCapabilitiesContext)?.capabilities ?? null;
49
+ }
50
+ function useServerCapabilitiesSettled() {
51
+ return useContext(ServerCapabilitiesContext)?.settled ?? false;
52
+ }
53
+ function useOptionalRefreshServerCapabilities() {
54
+ return useContext(ServerCapabilitiesContext)?.refresh ?? null;
55
+ }
56
+ function useCatalogServer() {
57
+ const server = useServer();
58
+ if (server.catalog == null) {
59
+ throw new Error("useCatalogServer requires AgentUIServer.catalog. Pass catalog to createTrueFoundryServer.");
60
+ }
61
+ return server.catalog;
62
+ }
63
+ function useOptionalCatalogServer() {
64
+ return useOptionalServer()?.catalog ?? null;
65
+ }
66
+ function useAgentSessionsServer() {
67
+ const sessions = useServer().sessions;
68
+ if (sessions == null) {
69
+ throw new Error("useAgentSessionsServer requires AgentUIServer.sessions.");
70
+ }
71
+ return sessions;
72
+ }
73
+ function useOptionalAgentSessionsServer() {
74
+ return useOptionalServer()?.sessions ?? null;
75
+ }
76
+ function useAgentMetricsServer() {
77
+ const metrics = useServer().metrics;
78
+ if (metrics == null) {
79
+ throw new Error("useAgentMetricsServer requires AgentUIServer.metrics.");
80
+ }
81
+ return metrics;
82
+ }
83
+ function useOptionalAgentMetricsServer() {
84
+ return useOptionalServer()?.metrics ?? null;
85
+ }
86
+ function useScheduleServer() {
87
+ const server = useServer();
88
+ if (server.schedules == null) {
89
+ throw new Error("useScheduleServer requires AgentUIServer.schedules. Pass schedules to createTrueFoundryServer.");
90
+ }
91
+ return server.schedules;
92
+ }
93
+ function useOptionalScheduleServer() {
94
+ return useOptionalServer()?.schedules ?? null;
95
+ }
96
+ function useOptionalPermissionsServer() {
97
+ return useOptionalServer()?.permissions ?? null;
98
+ }
99
+
100
+ // src/utils/sessionShareUrl.ts
101
+ var SESSION_ID_QUERY = "sessionId";
102
+ var AGENT_ID_QUERY = "agentId";
103
+ var AGENT_TAB_QUERY = "tab";
104
+ var SESSIONS_VIEW_QUERY = "view";
105
+ var SESSIONS_VIEW_VALUE = "sessions";
106
+ var SESSION_START_TIME_QUERY = "s_sts";
107
+ var SESSION_END_TIME_QUERY = "s_ets";
108
+ var SESSION_TIME_WINDOW_QUERY = "s_tw";
109
+ var SESSION_TIME_BUFFER_MS = 5 * 60 * 1e3;
110
+ var SESSION_CUSTOM_RANGE_MAX_DAYS = 70;
111
+ var DEFAULT_SESSION_TIME_WINDOW_MS = 30 * 24 * 60 * 60 * 1e3;
112
+ var DEFAULT_METRICS_TIME_WINDOW_MS = 24 * 60 * 60 * 1e3;
113
+ function parseLibraryAgentTab(value) {
114
+ if (value === "overview" || value === "sessions" || value === "schedules" || value === "code" || value === "metrics") {
115
+ return value;
116
+ }
117
+ return null;
118
+ }
119
+ function nonEmpty(value) {
120
+ return value != null && value.length > 0 ? value : null;
121
+ }
122
+ function parseMs(value) {
123
+ if (value == null || value.length === 0) return null;
124
+ const parsed = Number(value);
125
+ return Number.isFinite(parsed) ? parsed : null;
126
+ }
127
+ function defaultSessionTimeRange(now = Date.now()) {
128
+ return {
129
+ startTs: now - DEFAULT_SESSION_TIME_WINDOW_MS,
130
+ endTs: now,
131
+ timeWindowMs: DEFAULT_SESSION_TIME_WINDOW_MS
132
+ };
133
+ }
134
+ function defaultMetricsTimeRange(now = Date.now()) {
135
+ return {
136
+ startTs: now - DEFAULT_METRICS_TIME_WINDOW_MS,
137
+ endTs: now,
138
+ timeWindowMs: DEFAULT_METRICS_TIME_WINDOW_MS
139
+ };
140
+ }
141
+ function sessionTimeRangeFromCreatedAt(createdAt) {
142
+ const createdAtMs = new Date(createdAt).getTime();
143
+ if (Number.isNaN(createdAtMs)) return null;
144
+ return {
145
+ startTs: createdAtMs - SESSION_TIME_BUFFER_MS,
146
+ endTs: createdAtMs + SESSION_TIME_BUFFER_MS
147
+ };
148
+ }
149
+ function resolveSessionTimeRange(range, now = Date.now()) {
150
+ if (range.timeWindowMs != null) {
151
+ return { startTs: now - range.timeWindowMs, endTs: now };
152
+ }
153
+ return { startTs: range.startTs, endTs: range.endTs };
154
+ }
155
+ function readSessionShareSearch(search) {
156
+ const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
157
+ const startTs = parseMs(params.get(SESSION_START_TIME_QUERY));
158
+ const endTs = parseMs(params.get(SESSION_END_TIME_QUERY));
159
+ const timeWindowMs = parseMs(params.get(SESSION_TIME_WINDOW_QUERY));
160
+ const view = params.get(SESSIONS_VIEW_QUERY);
161
+ const now = Date.now();
162
+ return {
163
+ sessionId: nonEmpty(params.get(SESSION_ID_QUERY)),
164
+ agentId: nonEmpty(params.get(AGENT_ID_QUERY)),
165
+ tab: parseLibraryAgentTab(params.get(AGENT_TAB_QUERY)),
166
+ view: view === SESSIONS_VIEW_VALUE ? SESSIONS_VIEW_VALUE : null,
167
+ timeRange: startTs != null && endTs != null ? { startTs, endTs } : timeWindowMs != null ? { startTs: now - timeWindowMs, endTs: now, timeWindowMs } : null
168
+ };
169
+ }
170
+ function libraryAgentTabFromSearch(share, agentId) {
171
+ if (share.tab != null) return share.tab;
172
+ return share.sessionId != null && share.agentId === agentId ? "sessions" : "overview";
173
+ }
174
+ function writeSessionShareSearch(params, next) {
175
+ if (next.sessionId === null) params.delete(SESSION_ID_QUERY);
176
+ else if (next.sessionId != null) params.set(SESSION_ID_QUERY, next.sessionId);
177
+ if (next.agentId === null) params.delete(AGENT_ID_QUERY);
178
+ else if (next.agentId != null) params.set(AGENT_ID_QUERY, next.agentId);
179
+ if (next.tab === null) params.delete(AGENT_TAB_QUERY);
180
+ else if (next.tab != null) params.set(AGENT_TAB_QUERY, next.tab);
181
+ if (next.view === null) params.delete(SESSIONS_VIEW_QUERY);
182
+ else if (next.view != null) params.set(SESSIONS_VIEW_QUERY, next.view);
183
+ if (next.timeRange === null) {
184
+ params.delete(SESSION_START_TIME_QUERY);
185
+ params.delete(SESSION_END_TIME_QUERY);
186
+ params.delete(SESSION_TIME_WINDOW_QUERY);
187
+ } else if (next.timeRange != null) {
188
+ if (next.timeRange.timeWindowMs != null) {
189
+ params.set(SESSION_TIME_WINDOW_QUERY, String(next.timeRange.timeWindowMs));
190
+ params.delete(SESSION_START_TIME_QUERY);
191
+ params.delete(SESSION_END_TIME_QUERY);
192
+ } else {
193
+ params.set(SESSION_START_TIME_QUERY, String(next.timeRange.startTs));
194
+ params.set(SESSION_END_TIME_QUERY, String(next.timeRange.endTs));
195
+ params.delete(SESSION_TIME_WINDOW_QUERY);
196
+ }
197
+ }
198
+ }
199
+ function buildAgentSessionShareUrl({
200
+ sessionId,
201
+ agentId,
202
+ createdAt,
203
+ view,
204
+ href = typeof window === "undefined" ? "" : window.location.href
205
+ }) {
206
+ const url = new URL(href);
207
+ writeSessionShareSearch(url.searchParams, {
208
+ sessionId,
209
+ agentId: agentId == null || agentId.length === 0 ? null : agentId,
210
+ ...view === void 0 ? {} : { view },
211
+ timeRange: createdAt == null ? void 0 : sessionTimeRangeFromCreatedAt(createdAt)
212
+ });
213
+ return url.toString();
214
+ }
215
+ var SESSION_SHARE_CHANGE_EVENT = "trueforge-session-share";
216
+ function replaceSessionShareSearch(next) {
217
+ const url = new URL(window.location.href);
218
+ writeSessionShareSearch(url.searchParams, next);
219
+ window.history.replaceState(window.history.state, "", url);
220
+ window.dispatchEvent(new Event(SESSION_SHARE_CHANGE_EVENT));
221
+ return url.search;
222
+ }
223
+
224
+ // src/server/serverChrome.ts
225
+ function isSettingsChromeEnabled({
226
+ catalog,
227
+ capabilities
228
+ }) {
229
+ return catalog != null && capabilities?.settings?.enabled === true;
230
+ }
231
+ function isSessionsChromeEnabled({ sessions }) {
232
+ return sessions != null;
233
+ }
234
+ function isSchedulesChromeEnabled({ schedules }) {
235
+ return schedules != null;
236
+ }
237
+ function isMetricsChromeEnabled({ metrics }) {
238
+ return metrics != null;
239
+ }
240
+ function toEffectiveRoutes({
241
+ routes,
242
+ catalog,
243
+ capabilities,
244
+ sessions,
245
+ schedules
246
+ }) {
247
+ const sessionsEnabled = isSessionsChromeEnabled({ sessions });
248
+ return {
249
+ ...routes,
250
+ settings: isSettingsChromeEnabled({ catalog, capabilities }) ? routes.settings : null,
251
+ sessionsBrowser: sessionsEnabled ? routes.sessionsBrowser : null,
252
+ libraryAgent: sessionsEnabled ? routes.libraryAgent : null,
253
+ schedules: isSchedulesChromeEnabled({ schedules }) ? routes.schedules : null
254
+ };
255
+ }
256
+
257
+ // src/server/ShellModeContext.tsx
258
+ import { createContext as createContext2, useCallback as useCallback2, useContext as useContext2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
259
+
260
+ // src/server/draftSpecPreferences.ts
261
+ var DRAFT_SPEC_PREFERENCES_STORAGE_KEY = "tfy-aui-draft-spec-preferences";
262
+ var CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY = "tfy-aui-chat-draft-spec-preferences";
263
+ var AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY = "tfy-aui-agent-draft-spec-preferences";
264
+ function isObject(value) {
265
+ return typeof value === "object" && value !== null;
266
+ }
267
+ function isMountList(value) {
268
+ return Array.isArray(value) && value.every(isObject);
269
+ }
270
+ function isAgentSpec(value) {
271
+ if (!isObject(value)) return false;
272
+ const model = Reflect.get(value, "model");
273
+ if (!isObject(model) || typeof Reflect.get(model, "name") !== "string") return false;
274
+ const params = Reflect.get(model, "params");
275
+ if (params !== void 0 && !isObject(params)) return false;
276
+ const skills = Reflect.get(value, "skills");
277
+ if (skills !== void 0 && !isMountList(skills)) return false;
278
+ const mcpServers = Reflect.get(value, "mcpServers");
279
+ if (mcpServers !== void 0 && !isMountList(mcpServers)) return false;
280
+ const config = Reflect.get(value, "config");
281
+ return config === void 0 || isObject(config);
282
+ }
283
+ function isStoredDraftSpecPreferences(value) {
284
+ return isObject(value) && Reflect.get(value, "version") === 1 && isAgentSpec(Reflect.get(value, "spec"));
285
+ }
286
+ function storageKeyForKind(kind) {
287
+ return kind === "chat" ? CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY : AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY;
288
+ }
289
+ function selectChatDraftSpecPreferences(spec) {
290
+ return {
291
+ model: spec.model,
292
+ ...spec.skills !== void 0 ? { skills: spec.skills } : {},
293
+ ...spec.mcpServers !== void 0 ? { mcpServers: spec.mcpServers } : {}
294
+ };
295
+ }
296
+ function selectAgentDraftSpecPreferences(spec) {
297
+ return {
298
+ ...selectChatDraftSpecPreferences(spec),
299
+ ...spec.config !== void 0 ? { config: spec.config } : {}
300
+ };
301
+ }
302
+ function selectDraftSpecPreferences(spec, kind) {
303
+ return kind === "chat" ? selectChatDraftSpecPreferences(spec) : selectAgentDraftSpecPreferences(spec);
304
+ }
305
+ function readSandboxEnabled(spec) {
306
+ if (spec.config === void 0) return void 0;
307
+ const sandbox = Reflect.get(spec.config, "sandbox");
308
+ if (!isObject(sandbox)) return void 0;
309
+ const enabled = Reflect.get(sandbox, "enabled");
310
+ return typeof enabled === "boolean" ? enabled : void 0;
311
+ }
312
+ function withCapabilitiesSandbox(spec, sandboxEnabled) {
313
+ if (sandboxEnabled !== false || readSandboxEnabled(spec) === false) return spec;
314
+ const config = {
315
+ ...spec.config,
316
+ sandbox: { ...spec.config?.sandbox, enabled: false }
317
+ };
318
+ return {
319
+ ...spec,
320
+ config
321
+ };
322
+ }
323
+ function readStoredSpec(key) {
324
+ if (typeof window === "undefined") return null;
325
+ try {
326
+ const stored = JSON.parse(window.localStorage.getItem(key) ?? "null");
327
+ return isStoredDraftSpecPreferences(stored) ? stored.spec : null;
328
+ } catch {
329
+ return null;
330
+ }
331
+ }
332
+ function writeStoredSpec(key, spec) {
333
+ if (typeof window === "undefined") return false;
334
+ try {
335
+ const stored = { version: 1, spec };
336
+ window.localStorage.setItem(key, JSON.stringify(stored));
337
+ return true;
338
+ } catch {
339
+ return false;
340
+ }
341
+ }
342
+ function migrateLegacyDraftPreferences() {
343
+ if (typeof window === "undefined") return;
344
+ const legacy = readStoredSpec(DRAFT_SPEC_PREFERENCES_STORAGE_KEY);
345
+ if (legacy == null) return;
346
+ const chatReady = readStoredSpec(CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY) != null || writeStoredSpec(CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY, selectChatDraftSpecPreferences(legacy));
347
+ const agentReady = readStoredSpec(AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY) != null || writeStoredSpec(AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY, selectAgentDraftSpecPreferences(legacy));
348
+ if (!chatReady || !agentReady) return;
349
+ try {
350
+ window.localStorage.removeItem(DRAFT_SPEC_PREFERENCES_STORAGE_KEY);
351
+ } catch {
352
+ }
353
+ }
354
+ function readDraftSpecPreferences(kind) {
355
+ migrateLegacyDraftPreferences();
356
+ const stored = readStoredSpec(storageKeyForKind(kind));
357
+ return stored == null ? null : selectDraftSpecPreferences(stored, kind);
358
+ }
359
+ function writeDraftSpecPreferences(kind, spec) {
360
+ writeStoredSpec(storageKeyForKind(kind), selectDraftSpecPreferences(spec, kind));
361
+ }
362
+
363
+ // src/server/ShellModeContext.tsx
364
+ import { jsx as jsx2 } from "react/jsx-runtime";
365
+ var DEFAULT_AGENT_CONFIG = {
366
+ mode: "AgentLibraryWithComposer"
367
+ };
368
+ var ShellModeContext = createContext2(null);
369
+ var FALLBACK_MUTABLE_SPEC = {
370
+ model: { name: "openai-main/gpt-4.1" }
371
+ };
372
+ function mutableSeedFromConfig(config) {
373
+ if (config.mode === "AgentComposer" || config.mode === "AgentLibraryWithComposer") {
374
+ return config.defaultAgentSpec ?? FALLBACK_MUTABLE_SPEC;
375
+ }
376
+ return FALLBACK_MUTABLE_SPEC;
377
+ }
378
+ function initialMode(config, mutableSeed) {
379
+ switch (config.mode) {
380
+ case "SingleAgent":
381
+ return {
382
+ status: "active",
383
+ isMutable: false,
384
+ isCreateAgent: false,
385
+ agentId: config.name,
386
+ agentName: config.name,
387
+ locked: true
388
+ };
389
+ case "AgentLibrary":
390
+ return { status: "idle" };
391
+ case "AgentComposer":
392
+ case "AgentLibraryWithComposer":
393
+ return {
394
+ status: "active",
395
+ isMutable: true,
396
+ isCreateAgent: false,
397
+ agentSpec: mutableSeed,
398
+ locked: false
399
+ };
400
+ }
401
+ }
402
+ function resolveMutableIsCreateAgent(req) {
403
+ if (req.isCreateAgent !== void 0) return req.isCreateAgent;
404
+ return req.agentId != null || req.agentName != null;
405
+ }
406
+ function libraryAgentId(agent) {
407
+ return agent.agentId ?? agent.name;
408
+ }
409
+ function ShellModeProvider({
410
+ agentConfig = DEFAULT_AGENT_CONFIG,
411
+ initialSettingsOpen = false,
412
+ children
413
+ }) {
414
+ const capabilities = useServerCapabilities();
415
+ const catalog = useOptionalCatalogServer();
416
+ const refreshCapabilities = useOptionalRefreshServerCapabilities();
417
+ const sessionsServer = useOptionalAgentSessionsServer();
418
+ const scheduleServer = useOptionalScheduleServer();
419
+ const chatSeedRef = useRef2(
420
+ readDraftSpecPreferences("chat") ?? selectDraftSpecPreferences(mutableSeedFromConfig(agentConfig), "chat")
421
+ );
422
+ const agentSeedRef = useRef2(
423
+ readDraftSpecPreferences("agent") ?? selectDraftSpecPreferences(mutableSeedFromConfig(agentConfig), "agent")
424
+ );
425
+ const isLibraryEnabled = agentConfig.mode === "AgentLibrary" || agentConfig.mode === "AgentLibraryWithComposer";
426
+ const isComposerEnabled = agentConfig.mode === "AgentComposer" || agentConfig.mode === "AgentLibraryWithComposer";
427
+ const isNewChatEnabled = agentConfig.mode !== "AgentLibrary";
428
+ const locked = agentConfig.mode === "SingleAgent";
429
+ const [mode, setMode] = useState2(() => initialMode(agentConfig, chatSeedRef.current));
430
+ const [mutableEpoch, setMutableEpoch] = useState2(0);
431
+ const [clearEpoch, setClearEpoch] = useState2(0);
432
+ const [agentsListEpoch, setAgentsListEpoch] = useState2(0);
433
+ const [settingsOpenState, setSettingsOpenState] = useState2(initialSettingsOpen);
434
+ const [settingsSection, setSettingsSection] = useState2("models");
435
+ const [agentConfigOpenState, setAgentConfigOpenState] = useState2(false);
436
+ const [libraryOpenState, setLibraryOpenState] = useState2(false);
437
+ const [sessionsOpenState, setSessionsOpenState] = useState2(false);
438
+ const [libraryAgentId2, setLibraryAgentId] = useState2(null);
439
+ const [schedulesOpenState, setSchedulesOpenState] = useState2(false);
440
+ const [historyAgentFilter, setHistoryAgentFilter] = useState2(null);
441
+ const [pendingSessionId, setPendingSessionId] = useState2(void 0);
442
+ const [pendingSessionEpoch, setPendingSessionEpoch] = useState2(0);
443
+ const settingsEnabled = isSettingsChromeEnabled({ catalog, capabilities });
444
+ const settingsOpen = settingsEnabled && settingsOpenState;
445
+ const sessionsEnabled = isSessionsChromeEnabled({ sessions: sessionsServer });
446
+ const schedulesEnabled = isSchedulesChromeEnabled({ schedules: scheduleServer });
447
+ const schedulesOpen = schedulesEnabled && schedulesOpenState;
448
+ const libraryOpen = isLibraryEnabled && libraryOpenState;
449
+ const sessionsOpen = sessionsEnabled && sessionsOpenState;
450
+ const setSessionsOpen = useCallback2(
451
+ (open) => {
452
+ if (open) {
453
+ setSettingsOpenState(false);
454
+ setAgentConfigOpenState(false);
455
+ setLibraryOpenState(false);
456
+ setLibraryAgentId(null);
457
+ setSchedulesOpenState(false);
458
+ } else {
459
+ replaceSessionShareSearch({ view: null });
460
+ }
461
+ setSessionsOpenState(sessionsEnabled && open);
462
+ },
463
+ [sessionsEnabled]
464
+ );
465
+ const setLibraryOpen = useCallback2(
466
+ (open) => {
467
+ if (!isLibraryEnabled) return;
468
+ if (open) {
469
+ setSettingsOpenState(false);
470
+ setAgentConfigOpenState(false);
471
+ setSessionsOpen(false);
472
+ setSchedulesOpenState(false);
473
+ }
474
+ setLibraryAgentId(null);
475
+ setLibraryOpenState(open);
476
+ },
477
+ [isLibraryEnabled, setSessionsOpen]
478
+ );
479
+ const openLibraryAgent = useCallback2(
480
+ (agentId) => {
481
+ if (!isLibraryEnabled || !sessionsEnabled) return;
482
+ setSettingsOpenState(false);
483
+ setAgentConfigOpenState(false);
484
+ setSessionsOpen(false);
485
+ setSchedulesOpenState(false);
486
+ setLibraryOpenState(true);
487
+ setLibraryAgentId(agentId);
488
+ },
489
+ [isLibraryEnabled, sessionsEnabled, setSessionsOpen]
490
+ );
491
+ const closeLibraryAgent = useCallback2(() => {
492
+ setLibraryAgentId(null);
493
+ }, []);
494
+ const setSettingsOpen = useCallback2(
495
+ (open, section) => {
496
+ if (section !== void 0) {
497
+ setSettingsSection(section);
498
+ }
499
+ if (open) {
500
+ setAgentConfigOpenState(false);
501
+ setLibraryOpenState(false);
502
+ setLibraryAgentId(null);
503
+ setSessionsOpen(false);
504
+ setSchedulesOpenState(false);
505
+ }
506
+ setSettingsOpenState(settingsEnabled && open);
507
+ },
508
+ [setSessionsOpen, settingsEnabled]
509
+ );
510
+ const setAgentConfigOpen = useCallback2(
511
+ (open) => {
512
+ if (open) {
513
+ setSettingsOpenState(false);
514
+ setLibraryOpenState(false);
515
+ setLibraryAgentId(null);
516
+ setSessionsOpen(false);
517
+ setSchedulesOpenState(false);
518
+ }
519
+ setAgentConfigOpenState(open);
520
+ },
521
+ [setSessionsOpen]
522
+ );
523
+ const setSchedulesOpen = useCallback2(
524
+ (open) => {
525
+ if (open) {
526
+ setSettingsOpenState(false);
527
+ setAgentConfigOpenState(false);
528
+ setLibraryOpenState(false);
529
+ setLibraryAgentId(null);
530
+ setSessionsOpen(false);
531
+ }
532
+ setSchedulesOpenState(schedulesEnabled && open);
533
+ },
534
+ [schedulesEnabled, setSessionsOpen]
535
+ );
536
+ useEffect2(() => {
537
+ if (catalog == null || capabilities?.settings?.enabled === false) {
538
+ setSettingsOpenState(false);
539
+ }
540
+ }, [capabilities?.settings?.enabled, catalog]);
541
+ useEffect2(() => {
542
+ if (!sessionsEnabled) {
543
+ setSessionsOpenState(false);
544
+ setLibraryAgentId(null);
545
+ }
546
+ }, [sessionsEnabled]);
547
+ useEffect2(() => {
548
+ if (!schedulesEnabled) {
549
+ setSchedulesOpenState(false);
550
+ }
551
+ }, [schedulesEnabled]);
552
+ const invalidateAgentsList = useCallback2(() => {
553
+ setAgentsListEpoch((n) => n + 1);
554
+ }, []);
555
+ const lockedAgentName = agentConfig.mode === "SingleAgent" ? agentConfig.name : "";
556
+ const effectiveMode = useMemo2(() => {
557
+ if (!locked) return mode;
558
+ return {
559
+ status: "active",
560
+ isMutable: false,
561
+ isCreateAgent: false,
562
+ agentId: lockedAgentName,
563
+ agentName: lockedAgentName,
564
+ locked: true
565
+ };
566
+ }, [locked, lockedAgentName, mode]);
567
+ const agentConfigOpen = effectiveMode.status === "active" && effectiveMode.isMutable && effectiveMode.isCreateAgent && agentConfigOpenState;
568
+ useEffect2(() => {
569
+ if (effectiveMode.status !== "active" || !effectiveMode.isMutable || !effectiveMode.isCreateAgent) {
570
+ setAgentConfigOpenState(false);
571
+ }
572
+ }, [effectiveMode]);
573
+ const listSessionsAgentId = useMemo2(() => {
574
+ if (locked) return lockedAgentName;
575
+ if (!isLibraryEnabled) return void 0;
576
+ return historyAgentFilter?.agentId;
577
+ }, [locked, lockedAgentName, isLibraryEnabled, historyAgentFilter]);
578
+ const bumpEpoch = useCallback2((isMutable) => {
579
+ if (isMutable) setMutableEpoch((n) => n + 1);
580
+ else setClearEpoch((n) => n + 1);
581
+ }, []);
582
+ const selectLibraryAgent = useCallback2(
583
+ (req) => {
584
+ if (req.isMutable) {
585
+ if (!isComposerEnabled) return;
586
+ setSettingsOpen(false);
587
+ setLibraryOpenState(false);
588
+ setLibraryAgentId(null);
589
+ setSessionsOpen(false);
590
+ setSchedulesOpen(false);
591
+ setPendingSessionId(void 0);
592
+ const isCreateAgent = resolveMutableIsCreateAgent(req);
593
+ const kind = isCreateAgent ? "agent" : "chat";
594
+ setMode({
595
+ status: "active",
596
+ isMutable: true,
597
+ isCreateAgent,
598
+ agentId: req.agentId,
599
+ agentName: req.agentName,
600
+ description: req.description,
601
+ agentSpec: req.agentSpec ?? (kind === "agent" ? agentSeedRef.current : chatSeedRef.current),
602
+ locked: false
603
+ });
604
+ setAgentConfigOpenState(isCreateAgent);
605
+ bumpEpoch(true);
606
+ return;
607
+ }
608
+ if (!isLibraryEnabled) return;
609
+ const agentName = req.agentName ?? req.agentId;
610
+ if (agentName == null) return;
611
+ setSettingsOpen(false);
612
+ setLibraryOpenState(false);
613
+ setLibraryAgentId(null);
614
+ setSessionsOpen(false);
615
+ setSchedulesOpen(false);
616
+ setPendingSessionId(void 0);
617
+ setAgentConfigOpenState(false);
618
+ setMode({
619
+ status: "active",
620
+ isMutable: false,
621
+ isCreateAgent: false,
622
+ agentId: req.agentId ?? agentName,
623
+ agentName,
624
+ locked: false
625
+ });
626
+ if (req.agentId != null) {
627
+ setHistoryAgentFilter({
628
+ agentId: req.agentId,
629
+ agentName,
630
+ intent: "try-agent"
631
+ });
632
+ } else {
633
+ setHistoryAgentFilter(null);
634
+ }
635
+ bumpEpoch(false);
636
+ },
637
+ [isComposerEnabled, isLibraryEnabled, bumpEpoch, setSettingsOpen, setSessionsOpen, setSchedulesOpen]
638
+ );
639
+ const bindMutableAgent = useCallback2(
640
+ (req) => {
641
+ if (!isComposerEnabled) return;
642
+ setMode((prev) => {
643
+ if (prev.status !== "active" || !prev.isMutable) return prev;
644
+ return {
645
+ status: "active",
646
+ isMutable: true,
647
+ isCreateAgent: true,
648
+ agentId: req.agentId,
649
+ agentName: req.agentName,
650
+ description: req.description,
651
+ agentSpec: req.agentSpec,
652
+ locked: false
653
+ };
654
+ });
655
+ },
656
+ [isComposerEnabled]
657
+ );
658
+ const selectAgent = useCallback2(
659
+ (name) => {
660
+ selectLibraryAgent({ isMutable: false, agentId: name, agentName: name });
661
+ },
662
+ [selectLibraryAgent]
663
+ );
664
+ const openDraft = useCallback2(() => {
665
+ if (!isComposerEnabled) return;
666
+ refreshCapabilities?.();
667
+ setHistoryAgentFilter(null);
668
+ selectLibraryAgent({ isMutable: true, isCreateAgent: false, agentSpec: chatSeedRef.current });
669
+ }, [isComposerEnabled, refreshCapabilities, selectLibraryAgent]);
670
+ const isActiveAgentBuilder = effectiveMode.status === "active" && effectiveMode.isMutable && effectiveMode.isCreateAgent;
671
+ const openAgentBuilder = useCallback2(() => {
672
+ if (!isComposerEnabled) return;
673
+ refreshCapabilities?.();
674
+ if (isActiveAgentBuilder) {
675
+ setSettingsOpen(false);
676
+ setLibraryOpenState(false);
677
+ setLibraryAgentId(null);
678
+ setSessionsOpen(false);
679
+ setSchedulesOpen(false);
680
+ setAgentConfigOpenState(true);
681
+ return;
682
+ }
683
+ selectLibraryAgent({ isMutable: true, isCreateAgent: true, agentSpec: agentSeedRef.current });
684
+ }, [
685
+ isActiveAgentBuilder,
686
+ isComposerEnabled,
687
+ refreshCapabilities,
688
+ selectLibraryAgent,
689
+ setSchedulesOpen,
690
+ setSessionsOpen,
691
+ setSettingsOpen
692
+ ]);
693
+ const sandboxEnabled = capabilities?.sandbox.enabled;
694
+ const rememberDraftSpec = useCallback2(
695
+ (agentSpec, kind = "chat") => {
696
+ const selected = selectDraftSpecPreferences(agentSpec, kind);
697
+ const preferences = kind === "agent" ? withCapabilitiesSandbox(selected, sandboxEnabled) : selected;
698
+ if (kind === "chat") {
699
+ chatSeedRef.current = preferences;
700
+ } else {
701
+ agentSeedRef.current = withCapabilitiesSandbox(agentSpec, sandboxEnabled);
702
+ }
703
+ writeDraftSpecPreferences(kind, preferences);
704
+ },
705
+ [sandboxEnabled]
706
+ );
707
+ const openHistorySession = useCallback2(
708
+ ({
709
+ sessionId,
710
+ agentName,
711
+ isMutable: isMutableOpt,
712
+ isCreateAgent: isCreateAgentOpt
713
+ }) => {
714
+ const isMutable = isMutableOpt ?? agentName == null;
715
+ if (isMutable) {
716
+ if (!isComposerEnabled) return;
717
+ } else if (locked) {
718
+ if (agentName == null || lockedAgentName !== agentName) return;
719
+ } else if (!isLibraryEnabled) {
720
+ return;
721
+ }
722
+ setSettingsOpen(false);
723
+ setLibraryOpenState(false);
724
+ setLibraryAgentId(null);
725
+ setSessionsOpen(false);
726
+ setSchedulesOpen(false);
727
+ setPendingSessionId(sessionId);
728
+ setPendingSessionEpoch((n) => n + 1);
729
+ if (isMutable) {
730
+ const isCreateAgent = isCreateAgentOpt === true;
731
+ setMode({
732
+ status: "active",
733
+ isMutable: true,
734
+ isCreateAgent,
735
+ agentSpec: isCreateAgent ? agentSeedRef.current : chatSeedRef.current,
736
+ locked: false
737
+ });
738
+ setAgentConfigOpenState(isCreateAgent);
739
+ return;
740
+ }
741
+ setAgentConfigOpenState(false);
742
+ setMode({
743
+ status: "active",
744
+ isMutable: false,
745
+ isCreateAgent: false,
746
+ locked: false,
747
+ ...agentName != null ? { agentId: agentName, agentName } : {}
748
+ });
749
+ },
750
+ [isLibraryEnabled, isComposerEnabled, locked, lockedAgentName, setSettingsOpen, setSessionsOpen, setSchedulesOpen]
751
+ );
752
+ const clearChat = useCallback2(() => {
753
+ if (effectiveMode.status === "idle") return;
754
+ setPendingSessionId(void 0);
755
+ if (effectiveMode.isMutable) {
756
+ const kind = effectiveMode.isCreateAgent ? "agent" : "chat";
757
+ setMode({
758
+ status: "active",
759
+ isMutable: true,
760
+ isCreateAgent: effectiveMode.isCreateAgent,
761
+ agentId: effectiveMode.agentId,
762
+ agentName: effectiveMode.agentName,
763
+ agentSpec: effectiveMode.agentSpec ?? (kind === "agent" ? agentSeedRef.current : chatSeedRef.current),
764
+ locked: false
765
+ });
766
+ setAgentConfigOpenState(effectiveMode.isCreateAgent);
767
+ bumpEpoch(true);
768
+ return;
769
+ }
770
+ bumpEpoch(false);
771
+ }, [effectiveMode, bumpEpoch]);
772
+ const openLibraryHome = useCallback2(() => {
773
+ if (!isLibraryEnabled || isComposerEnabled) return;
774
+ setPendingSessionId(void 0);
775
+ setSettingsOpen(false);
776
+ setLibraryOpenState(false);
777
+ setLibraryAgentId(null);
778
+ setSchedulesOpen(false);
779
+ setMode({ status: "idle" });
780
+ bumpEpoch(false);
781
+ }, [isLibraryEnabled, isComposerEnabled, setSettingsOpen, setSchedulesOpen, bumpEpoch]);
782
+ const runtimeKey = useMemo2(() => {
783
+ if (effectiveMode.status === "idle") return "idle";
784
+ return `chat:${mutableEpoch}:${clearEpoch}`;
785
+ }, [effectiveMode.status, mutableEpoch, clearEpoch]);
786
+ const value = useMemo2(
787
+ () => ({
788
+ mode: effectiveMode,
789
+ agentConfigMode: agentConfig.mode,
790
+ isLibraryEnabled,
791
+ isComposerEnabled,
792
+ isNewChatEnabled,
793
+ settingsOpen,
794
+ settingsSection,
795
+ setSettingsOpen,
796
+ agentConfigOpen,
797
+ setAgentConfigOpen,
798
+ libraryOpen,
799
+ libraryAgentId: libraryAgentId2,
800
+ setLibraryAgentId,
801
+ setLibraryOpen,
802
+ sessionsOpen,
803
+ setSessionsOpen,
804
+ openLibraryAgent,
805
+ closeLibraryAgent,
806
+ schedulesOpen,
807
+ setSchedulesOpen,
808
+ selectLibraryAgent,
809
+ bindMutableAgent,
810
+ selectAgent,
811
+ openDraft,
812
+ openAgentBuilder,
813
+ rememberDraftSpec,
814
+ openHistorySession,
815
+ clearChat,
816
+ openLibraryHome,
817
+ runtimeKey,
818
+ historyAgentFilter,
819
+ setHistoryAgentFilter,
820
+ listSessionsAgentId,
821
+ pendingSessionId,
822
+ pendingSessionEpoch,
823
+ agentsListEpoch,
824
+ invalidateAgentsList
825
+ }),
826
+ [
827
+ effectiveMode,
828
+ agentConfig.mode,
829
+ isLibraryEnabled,
830
+ isComposerEnabled,
831
+ isNewChatEnabled,
832
+ settingsOpen,
833
+ settingsSection,
834
+ setSettingsOpen,
835
+ agentConfigOpen,
836
+ setAgentConfigOpen,
837
+ libraryOpen,
838
+ libraryAgentId2,
839
+ setLibraryOpen,
840
+ sessionsOpen,
841
+ setSessionsOpen,
842
+ openLibraryAgent,
843
+ closeLibraryAgent,
844
+ schedulesOpen,
845
+ setSchedulesOpen,
846
+ selectLibraryAgent,
847
+ bindMutableAgent,
848
+ selectAgent,
849
+ openDraft,
850
+ openAgentBuilder,
851
+ rememberDraftSpec,
852
+ openHistorySession,
853
+ clearChat,
854
+ openLibraryHome,
855
+ runtimeKey,
856
+ historyAgentFilter,
857
+ listSessionsAgentId,
858
+ pendingSessionId,
859
+ pendingSessionEpoch,
860
+ agentsListEpoch,
861
+ invalidateAgentsList
862
+ ]
863
+ );
864
+ return /* @__PURE__ */ jsx2(ShellModeContext.Provider, { value, children });
865
+ }
866
+ function useShellMode() {
867
+ const ctx = useContext2(ShellModeContext);
868
+ if (ctx == null) {
869
+ throw new Error("useShellMode must be used within a ShellModeProvider.");
870
+ }
871
+ return ctx;
872
+ }
873
+ function useOptionalShellMode() {
874
+ return useContext2(ShellModeContext);
875
+ }
876
+ function shellIsMutable(mode) {
877
+ return mode.status === "active" && mode.isMutable;
878
+ }
879
+ function shellIsCreateAgent(mode) {
880
+ return mode.status === "active" && mode.isMutable && mode.isCreateAgent;
881
+ }
882
+
883
+ // src/utils/getErrorMessage.ts
884
+ function isRecord(value) {
885
+ return value != null && typeof value === "object";
886
+ }
887
+ function readNonEmptyString(value) {
888
+ return typeof value === "string" && value.trim() !== "" ? value : void 0;
889
+ }
890
+ var LITERAL_ESCAPE_PATTERN = /\\(?:[nrtbfv0'"\\]|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2})/;
891
+ var REAL_CONTROL_PATTERN = /[\n\t\b\f\v]/;
892
+ function decodeLiteralEscapes(text) {
893
+ let out = "";
894
+ for (let i = 0; i < text.length; i += 1) {
895
+ const char = text[i];
896
+ if (char !== "\\" || i + 1 >= text.length) {
897
+ out += char;
898
+ continue;
899
+ }
900
+ const next = text[i + 1];
901
+ switch (next) {
902
+ case "n":
903
+ out += "\n";
904
+ i += 1;
905
+ break;
906
+ case "t":
907
+ out += " ";
908
+ i += 1;
909
+ break;
910
+ case "r":
911
+ out += "\r";
912
+ i += 1;
913
+ break;
914
+ case "b":
915
+ out += "\b";
916
+ i += 1;
917
+ break;
918
+ case "f":
919
+ out += "\f";
920
+ i += 1;
921
+ break;
922
+ case "v":
923
+ out += "\v";
924
+ i += 1;
925
+ break;
926
+ case "0":
927
+ out += "\0";
928
+ i += 1;
929
+ break;
930
+ case "\\":
931
+ out += "\\";
932
+ i += 1;
933
+ break;
934
+ case '"':
935
+ out += '"';
936
+ i += 1;
937
+ break;
938
+ case "'":
939
+ out += "'";
940
+ i += 1;
941
+ break;
942
+ case "u": {
943
+ const hex = text.slice(i + 2, i + 6);
944
+ if (/^[0-9a-fA-F]{4}$/.test(hex)) {
945
+ out += String.fromCharCode(Number.parseInt(hex, 16));
946
+ i += 5;
947
+ } else {
948
+ out += char;
949
+ }
950
+ break;
951
+ }
952
+ case "x": {
953
+ const hex = text.slice(i + 2, i + 4);
954
+ if (/^[0-9a-fA-F]{2}$/.test(hex)) {
955
+ out += String.fromCharCode(Number.parseInt(hex, 16));
956
+ i += 3;
957
+ } else {
958
+ out += char;
959
+ }
960
+ break;
961
+ }
962
+ default:
963
+ out += char;
964
+ break;
965
+ }
966
+ }
967
+ return out;
968
+ }
969
+ function decodeErrorMessageEscapes(text) {
970
+ const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
971
+ if (REAL_CONTROL_PATTERN.test(normalized) || !LITERAL_ESCAPE_PATTERN.test(normalized)) {
972
+ return normalized;
973
+ }
974
+ return decodeLiteralEscapes(normalized).replace(/\r\n/g, "\n").replace(/\r/g, "\n");
975
+ }
976
+ function messageFromErrorShaped(value) {
977
+ if (!isRecord(value)) return void 0;
978
+ const direct = readNonEmptyString(value.message);
979
+ if (direct != null) return direct;
980
+ if (isRecord(value.error)) {
981
+ return readNonEmptyString(value.error.message);
982
+ }
983
+ return void 0;
984
+ }
985
+ function stringifyError(error) {
986
+ if (typeof error === "string") return error;
987
+ if (isRecord(error)) {
988
+ try {
989
+ return JSON.stringify(error);
990
+ } catch {
991
+ return Object.prototype.toString.call(error);
992
+ }
993
+ }
994
+ return String(error);
995
+ }
996
+ function getErrorMessage(error, fallback) {
997
+ if (typeof error === "string") {
998
+ const trimmed = error.trim();
999
+ if (trimmed !== "") return decodeErrorMessageEscapes(error);
1000
+ return fallback != null ? decodeErrorMessageEscapes(fallback) : decodeErrorMessageEscapes(error);
1001
+ }
1002
+ if (isRecord(error) && "body" in error) {
1003
+ const fromBody = messageFromErrorShaped(error.body);
1004
+ if (fromBody != null) return decodeErrorMessageEscapes(fromBody);
1005
+ if (error.body != null) {
1006
+ if (typeof error.body === "string") {
1007
+ const trimmed = error.body.trim();
1008
+ if (trimmed !== "") return decodeErrorMessageEscapes(error.body);
1009
+ } else {
1010
+ return stringifyError(error.body);
1011
+ }
1012
+ }
1013
+ }
1014
+ const fromShape = messageFromErrorShaped(error);
1015
+ if (fromShape != null) return decodeErrorMessageEscapes(fromShape);
1016
+ if (fallback != null) return decodeErrorMessageEscapes(fallback);
1017
+ return stringifyError(error);
1018
+ }
1019
+
1020
+ export {
1021
+ ServerProvider,
1022
+ useServer,
1023
+ useOptionalServer,
1024
+ useServerCapabilities,
1025
+ useServerCapabilitiesSettled,
1026
+ useOptionalRefreshServerCapabilities,
1027
+ useCatalogServer,
1028
+ useOptionalCatalogServer,
1029
+ useAgentSessionsServer,
1030
+ useOptionalAgentSessionsServer,
1031
+ useAgentMetricsServer,
1032
+ useOptionalAgentMetricsServer,
1033
+ useScheduleServer,
1034
+ useOptionalScheduleServer,
1035
+ useOptionalPermissionsServer,
1036
+ SESSION_CUSTOM_RANGE_MAX_DAYS,
1037
+ defaultSessionTimeRange,
1038
+ defaultMetricsTimeRange,
1039
+ sessionTimeRangeFromCreatedAt,
1040
+ resolveSessionTimeRange,
1041
+ readSessionShareSearch,
1042
+ libraryAgentTabFromSearch,
1043
+ writeSessionShareSearch,
1044
+ buildAgentSessionShareUrl,
1045
+ SESSION_SHARE_CHANGE_EVENT,
1046
+ replaceSessionShareSearch,
1047
+ withCapabilitiesSandbox,
1048
+ isSettingsChromeEnabled,
1049
+ isSessionsChromeEnabled,
1050
+ isSchedulesChromeEnabled,
1051
+ isMetricsChromeEnabled,
1052
+ toEffectiveRoutes,
1053
+ DEFAULT_AGENT_CONFIG,
1054
+ libraryAgentId,
1055
+ ShellModeProvider,
1056
+ useShellMode,
1057
+ useOptionalShellMode,
1058
+ shellIsMutable,
1059
+ shellIsCreateAgent,
1060
+ getErrorMessage
1061
+ };
1062
+ //# sourceMappingURL=chunk-2GIZY3JJ.js.map