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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +14 -6
  3. package/dist/AgentCodeSnippets-NZOFJE57.js +74 -0
  4. package/dist/AgentCodeSnippets-NZOFJE57.js.map +1 -0
  5. package/dist/AgentMetricChart-JPU3MFQ2.js +15 -0
  6. package/dist/AgentOverview-EEBHJC32.js +167 -0
  7. package/dist/AgentOverview-EEBHJC32.js.map +1 -0
  8. package/dist/AgentSessionEventTimeline-26Z6IB3B.js +79 -0
  9. package/dist/AgentSessionEventTimeline-26Z6IB3B.js.map +1 -0
  10. package/dist/AgentSessionEventTimelineChart-CGCU7WBK.js +504 -0
  11. package/dist/AgentSessionEventTimelineChart-CGCU7WBK.js.map +1 -0
  12. package/dist/AgentSessions-3MPDZASK.js +275 -0
  13. package/dist/AgentSessions-3MPDZASK.js.map +1 -0
  14. package/dist/{ConnectorSettings-FXQ5B7TN.js → ConnectorSettings-MXFRWWR6.js} +8 -6
  15. package/dist/{ConnectorSettings-FXQ5B7TN.js.map → ConnectorSettings-MXFRWWR6.js.map} +1 -1
  16. package/dist/{DockLayout-LBNQJZNF.js → DockLayout-LM4AFMFY.js} +11 -10
  17. package/dist/{DockLayout-LBNQJZNF.js.map → DockLayout-LM4AFMFY.js.map} +1 -1
  18. package/dist/DrawerLayout-JR3O6RRB.js +184 -0
  19. package/dist/DrawerLayout-JR3O6RRB.js.map +1 -0
  20. package/dist/{ModelSettings-4L4LOQJA.js → ModelSettings-G7IFNC2Y.js} +8 -6
  21. package/dist/{ModelSettings-4L4LOQJA.js.map → ModelSettings-G7IFNC2Y.js.map} +1 -1
  22. package/dist/OpenUiFenceBlock-2TV5TQ6P.js +9 -0
  23. package/dist/OpenUiFenceBlock-2TV5TQ6P.js.map +1 -0
  24. package/dist/{SandboxSettings-Z4ZG6ZX4.js → SandboxSettings-NXAANMAX.js} +8 -6
  25. package/dist/{SandboxSettings-Z4ZG6ZX4.js.map → SandboxSettings-NXAANMAX.js.map} +1 -1
  26. package/dist/SchedulesPage-KKLUDO6B.js +15 -0
  27. package/dist/SchedulesPage-KKLUDO6B.js.map +1 -0
  28. package/dist/{SettingsBuilder-WF7ZWKQW.js → SettingsBuilder-L34IQ56S.js} +26 -22
  29. package/dist/SettingsBuilder-L34IQ56S.js.map +1 -0
  30. package/dist/{ShellRouteSync-T4WLY57Q.js → ShellRouteSync-CEBETGEJ.js} +95 -22
  31. package/dist/ShellRouteSync-CEBETGEJ.js.map +1 -0
  32. package/dist/SidebarLayout-A2HJPPHS.js +308 -0
  33. package/dist/SidebarLayout-A2HJPPHS.js.map +1 -0
  34. package/dist/{SkillSettings-3EPPC3IT.js → SkillSettings-FGGMSUNO.js} +8 -6
  35. package/dist/{SkillSettings-3EPPC3IT.js.map → SkillSettings-FGGMSUNO.js.map} +1 -1
  36. package/dist/{TrueForgeUIWithRouter-NZ4FGPE4.js → TrueForgeUIWithRouter-MZVJWJMB.js} +14 -10
  37. package/dist/{TrueForgeUIWithRouter-NZ4FGPE4.js.map → TrueForgeUIWithRouter-MZVJWJMB.js.map} +1 -1
  38. package/dist/{WidgetLayout-3QZ357FL.js → WidgetLayout-6QM45OQQ.js} +17 -13
  39. package/dist/WidgetLayout-6QM45OQQ.js.map +1 -0
  40. package/dist/chunk-2XPPBEYF.js +74 -0
  41. package/dist/chunk-2XPPBEYF.js.map +1 -0
  42. package/dist/chunk-6O6FWUDW.js +1376 -0
  43. package/dist/chunk-6O6FWUDW.js.map +1 -0
  44. package/dist/chunk-7Z2C2K7F.js +578 -0
  45. package/dist/chunk-7Z2C2K7F.js.map +1 -0
  46. package/dist/{chunk-WREC7D54.js → chunk-CYHJDKFB.js} +115 -32
  47. package/dist/chunk-CYHJDKFB.js.map +1 -0
  48. package/dist/chunk-DJUFS2BW.js +27 -0
  49. package/dist/chunk-DJUFS2BW.js.map +1 -0
  50. package/dist/chunk-DMMZSZTN.js +252 -0
  51. package/dist/chunk-DMMZSZTN.js.map +1 -0
  52. package/dist/chunk-FJW36PD7.js +180 -0
  53. package/dist/chunk-FJW36PD7.js.map +1 -0
  54. package/dist/chunk-M62XY4NC.js +555 -0
  55. package/dist/chunk-M62XY4NC.js.map +1 -0
  56. package/dist/{chunk-B52K63AW.js → chunk-MPNSO7E6.js} +2 -2
  57. package/dist/{chunk-CFLVPV5M.js → chunk-QC42MLAK.js} +7 -2
  58. package/dist/chunk-QC42MLAK.js.map +1 -0
  59. package/dist/chunk-RDXBMTP5.js +32 -0
  60. package/dist/chunk-RDXBMTP5.js.map +1 -0
  61. package/dist/chunk-SFZNIO6U.js +18 -0
  62. package/dist/chunk-SFZNIO6U.js.map +1 -0
  63. package/dist/chunk-U7KURWW3.js +840 -0
  64. package/dist/chunk-U7KURWW3.js.map +1 -0
  65. package/dist/chunk-WVE3F724.js +200 -0
  66. package/dist/chunk-WVE3F724.js.map +1 -0
  67. package/dist/{chunk-FJ5RSSMA.js → chunk-XAU7QFG3.js} +178 -36
  68. package/dist/chunk-XAU7QFG3.js.map +1 -0
  69. package/dist/chunk-Y6S4OVVQ.js +16 -0
  70. package/dist/chunk-Y6S4OVVQ.js.map +1 -0
  71. package/dist/chunk-ZKNUMH2M.js +119 -0
  72. package/dist/chunk-ZKNUMH2M.js.map +1 -0
  73. package/dist/chunk-ZTMKFZQ3.js +13214 -0
  74. package/dist/chunk-ZTMKFZQ3.js.map +1 -0
  75. package/dist/{createTrueFoundryServer-B72bU-J7.d.ts → createTrueFoundryServer-CmZnBh_l.d.ts} +15 -4
  76. package/dist/index.d.ts +1002 -22
  77. package/dist/index.js +689 -67
  78. package/dist/index.js.map +1 -1
  79. package/dist/plugins/trueforge-agent-server-adapter/index.d.ts +552 -8
  80. package/dist/plugins/trueforge-agent-server-adapter/index.js +503 -188
  81. package/dist/plugins/trueforge-agent-server-adapter/index.js.map +1 -1
  82. package/dist/styles.css +1 -1
  83. package/package.json +8 -7
  84. package/dist/DrawerLayout-Q6UK4VMI.js +0 -159
  85. package/dist/DrawerLayout-Q6UK4VMI.js.map +0 -1
  86. package/dist/OpenUiFenceBlock-6UIIAVBX.js +0 -9
  87. package/dist/SettingsBuilder-WF7ZWKQW.js.map +0 -1
  88. package/dist/ShellRouteSync-T4WLY57Q.js.map +0 -1
  89. package/dist/SidebarLayout-3WZ3CVON.js +0 -256
  90. package/dist/SidebarLayout-3WZ3CVON.js.map +0 -1
  91. package/dist/WidgetLayout-3QZ357FL.js.map +0 -1
  92. package/dist/chunk-36KOSC2J.js +0 -567
  93. package/dist/chunk-36KOSC2J.js.map +0 -1
  94. package/dist/chunk-3S6KHO7H.js +0 -2121
  95. package/dist/chunk-3S6KHO7H.js.map +0 -1
  96. package/dist/chunk-7L63OK3O.js +0 -91
  97. package/dist/chunk-7L63OK3O.js.map +0 -1
  98. package/dist/chunk-CFLVPV5M.js.map +0 -1
  99. package/dist/chunk-FJ5RSSMA.js.map +0 -1
  100. package/dist/chunk-OSV3HI5M.js +0 -6891
  101. package/dist/chunk-OSV3HI5M.js.map +0 -1
  102. package/dist/chunk-WQULF5AT.js +0 -460
  103. package/dist/chunk-WQULF5AT.js.map +0 -1
  104. package/dist/chunk-WREC7D54.js.map +0 -1
  105. package/dist/chunk-YIWUG6MC.js +0 -101
  106. package/dist/chunk-YIWUG6MC.js.map +0 -1
  107. package/dist/chunk-ZXOADNF3.js +0 -75
  108. package/dist/chunk-ZXOADNF3.js.map +0 -1
  109. /package/dist/{OpenUiFenceBlock-6UIIAVBX.js.map → AgentMetricChart-JPU3MFQ2.js.map} +0 -0
  110. /package/dist/{chunk-B52K63AW.js.map → chunk-MPNSO7E6.js.map} +0 -0
@@ -0,0 +1,840 @@
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 cancelActiveRequestRef = useRef(null);
9
+ const refreshCapabilities = useCallback(() => {
10
+ cancelActiveRequestRef.current?.();
11
+ let cancelled = false;
12
+ cancelActiveRequestRef.current = () => {
13
+ cancelled = true;
14
+ };
15
+ void server.getCapabilities().then((response) => {
16
+ if (!cancelled) setCapabilities(response.data);
17
+ }).catch(() => {
18
+ });
19
+ }, [server]);
20
+ useEffect(() => {
21
+ setCapabilities(null);
22
+ refreshCapabilities();
23
+ return () => {
24
+ cancelActiveRequestRef.current?.();
25
+ };
26
+ }, [refreshCapabilities]);
27
+ const capabilitiesValue = useMemo(
28
+ () => ({ capabilities, refresh: refreshCapabilities }),
29
+ [capabilities, refreshCapabilities]
30
+ );
31
+ return /* @__PURE__ */ jsx(ServerContext.Provider, { value: server, children: /* @__PURE__ */ jsx(ServerCapabilitiesContext.Provider, { value: capabilitiesValue, children }) });
32
+ }
33
+ function useServer() {
34
+ const server = useContext(ServerContext);
35
+ if (server == null) {
36
+ throw new Error("useServer must be used within a ServerProvider.");
37
+ }
38
+ return server;
39
+ }
40
+ function useOptionalServer() {
41
+ return useContext(ServerContext);
42
+ }
43
+ function useServerCapabilities() {
44
+ return useContext(ServerCapabilitiesContext)?.capabilities ?? null;
45
+ }
46
+ function useOptionalRefreshServerCapabilities() {
47
+ return useContext(ServerCapabilitiesContext)?.refresh ?? null;
48
+ }
49
+ function useCatalogServer() {
50
+ const server = useServer();
51
+ if (server.catalog == null) {
52
+ throw new Error("useCatalogServer requires AgentUIServer.catalog. Pass catalog to createTrueFoundryServer.");
53
+ }
54
+ return server.catalog;
55
+ }
56
+ function useOptionalCatalogServer() {
57
+ return useOptionalServer()?.catalog ?? null;
58
+ }
59
+ function useAgentSessionsServer() {
60
+ const sessions = useServer().sessions;
61
+ if (sessions == null) {
62
+ throw new Error("useAgentSessionsServer requires AgentUIServer.sessions.");
63
+ }
64
+ return sessions;
65
+ }
66
+ function useOptionalAgentSessionsServer() {
67
+ return useOptionalServer()?.sessions ?? null;
68
+ }
69
+ function useAgentMetricsServer() {
70
+ const metrics = useServer().metrics;
71
+ if (metrics == null) {
72
+ throw new Error("useAgentMetricsServer requires AgentUIServer.metrics.");
73
+ }
74
+ return metrics;
75
+ }
76
+ function useOptionalAgentMetricsServer() {
77
+ return useOptionalServer()?.metrics ?? null;
78
+ }
79
+ function useScheduleServer() {
80
+ const server = useServer();
81
+ if (server.schedules == null) {
82
+ throw new Error("useScheduleServer requires AgentUIServer.schedules. Pass schedules to createTrueFoundryServer.");
83
+ }
84
+ return server.schedules;
85
+ }
86
+ function useOptionalScheduleServer() {
87
+ return useOptionalServer()?.schedules ?? null;
88
+ }
89
+
90
+ // src/utils/sessionShareUrl.ts
91
+ var SESSION_ID_QUERY = "sessionId";
92
+ var AGENT_ID_QUERY = "agentId";
93
+ var AGENT_TAB_QUERY = "tab";
94
+ var SESSIONS_VIEW_QUERY = "view";
95
+ var SESSIONS_VIEW_VALUE = "sessions";
96
+ var SESSION_START_TIME_QUERY = "s_sts";
97
+ var SESSION_END_TIME_QUERY = "s_ets";
98
+ var SESSION_TIME_WINDOW_QUERY = "s_tw";
99
+ var SESSION_TIME_BUFFER_MS = 5 * 60 * 1e3;
100
+ var SESSION_CUSTOM_RANGE_MAX_DAYS = 70;
101
+ var DEFAULT_SESSION_TIME_WINDOW_MS = 30 * 24 * 60 * 60 * 1e3;
102
+ function parseLibraryAgentTab(value) {
103
+ if (value === "overview" || value === "sessions" || value === "code" || value === "metrics") return value;
104
+ return null;
105
+ }
106
+ function nonEmpty(value) {
107
+ return value != null && value.length > 0 ? value : null;
108
+ }
109
+ function parseMs(value) {
110
+ if (value == null || value.length === 0) return null;
111
+ const parsed = Number(value);
112
+ return Number.isFinite(parsed) ? parsed : null;
113
+ }
114
+ function defaultSessionTimeRange(now = Date.now()) {
115
+ return {
116
+ startTs: now - DEFAULT_SESSION_TIME_WINDOW_MS,
117
+ endTs: now,
118
+ timeWindowMs: DEFAULT_SESSION_TIME_WINDOW_MS
119
+ };
120
+ }
121
+ function sessionTimeRangeFromCreatedAt(createdAt) {
122
+ const createdAtMs = new Date(createdAt).getTime();
123
+ if (Number.isNaN(createdAtMs)) return null;
124
+ return {
125
+ startTs: createdAtMs - SESSION_TIME_BUFFER_MS,
126
+ endTs: createdAtMs + SESSION_TIME_BUFFER_MS
127
+ };
128
+ }
129
+ function resolveSessionTimeRange(range, now = Date.now()) {
130
+ if (range.timeWindowMs != null) {
131
+ return { startTs: now - range.timeWindowMs, endTs: now };
132
+ }
133
+ return { startTs: range.startTs, endTs: range.endTs };
134
+ }
135
+ function readSessionShareSearch(search) {
136
+ const params = new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
137
+ const startTs = parseMs(params.get(SESSION_START_TIME_QUERY));
138
+ const endTs = parseMs(params.get(SESSION_END_TIME_QUERY));
139
+ const timeWindowMs = parseMs(params.get(SESSION_TIME_WINDOW_QUERY));
140
+ const view = params.get(SESSIONS_VIEW_QUERY);
141
+ return {
142
+ sessionId: nonEmpty(params.get(SESSION_ID_QUERY)),
143
+ agentId: nonEmpty(params.get(AGENT_ID_QUERY)),
144
+ tab: parseLibraryAgentTab(params.get(AGENT_TAB_QUERY)),
145
+ view: view === SESSIONS_VIEW_VALUE ? SESSIONS_VIEW_VALUE : null,
146
+ timeRange: startTs != null && endTs != null ? { startTs, endTs } : timeWindowMs != null ? { startTs: Date.now() - timeWindowMs, endTs: Date.now(), timeWindowMs } : null
147
+ };
148
+ }
149
+ function libraryAgentTabFromSearch(share, agentId) {
150
+ if (share.tab != null) return share.tab;
151
+ return share.sessionId != null && share.agentId === agentId ? "sessions" : "overview";
152
+ }
153
+ function writeSessionShareSearch(params, next) {
154
+ if (next.sessionId === null) params.delete(SESSION_ID_QUERY);
155
+ else if (next.sessionId != null) params.set(SESSION_ID_QUERY, next.sessionId);
156
+ if (next.agentId === null) params.delete(AGENT_ID_QUERY);
157
+ else if (next.agentId != null) params.set(AGENT_ID_QUERY, next.agentId);
158
+ if (next.tab === null) params.delete(AGENT_TAB_QUERY);
159
+ else if (next.tab != null) params.set(AGENT_TAB_QUERY, next.tab);
160
+ if (next.view === null) params.delete(SESSIONS_VIEW_QUERY);
161
+ else if (next.view != null) params.set(SESSIONS_VIEW_QUERY, next.view);
162
+ if (next.timeRange === null) {
163
+ params.delete(SESSION_START_TIME_QUERY);
164
+ params.delete(SESSION_END_TIME_QUERY);
165
+ params.delete(SESSION_TIME_WINDOW_QUERY);
166
+ } else if (next.timeRange != null) {
167
+ if (next.timeRange.timeWindowMs != null) {
168
+ params.set(SESSION_TIME_WINDOW_QUERY, String(next.timeRange.timeWindowMs));
169
+ params.delete(SESSION_START_TIME_QUERY);
170
+ params.delete(SESSION_END_TIME_QUERY);
171
+ } else {
172
+ params.set(SESSION_START_TIME_QUERY, String(next.timeRange.startTs));
173
+ params.set(SESSION_END_TIME_QUERY, String(next.timeRange.endTs));
174
+ params.delete(SESSION_TIME_WINDOW_QUERY);
175
+ }
176
+ }
177
+ }
178
+ function buildAgentSessionShareUrl({
179
+ sessionId,
180
+ agentId,
181
+ createdAt,
182
+ view,
183
+ href = typeof window === "undefined" ? "" : window.location.href
184
+ }) {
185
+ const url = new URL(href);
186
+ writeSessionShareSearch(url.searchParams, {
187
+ sessionId,
188
+ agentId: agentId == null || agentId.length === 0 ? null : agentId,
189
+ ...view === void 0 ? {} : { view },
190
+ timeRange: createdAt == null ? void 0 : sessionTimeRangeFromCreatedAt(createdAt)
191
+ });
192
+ return url.toString();
193
+ }
194
+ var SESSION_SHARE_CHANGE_EVENT = "trueforge-session-share";
195
+ function replaceSessionShareSearch(next) {
196
+ const url = new URL(window.location.href);
197
+ writeSessionShareSearch(url.searchParams, next);
198
+ window.history.replaceState(window.history.state, "", url);
199
+ window.dispatchEvent(new Event(SESSION_SHARE_CHANGE_EVENT));
200
+ return url.search;
201
+ }
202
+
203
+ // src/server/settingsChrome.ts
204
+ function isSettingsChromeEnabled({
205
+ catalog,
206
+ capabilities
207
+ }) {
208
+ return catalog != null && capabilities?.settings?.enabled !== false;
209
+ }
210
+
211
+ // src/server/ShellModeContext.tsx
212
+ import { createContext as createContext2, useCallback as useCallback2, useContext as useContext2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
213
+
214
+ // src/server/draftSpecPreferences.ts
215
+ var DRAFT_SPEC_PREFERENCES_STORAGE_KEY = "tfy-aui-draft-spec-preferences";
216
+ var CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY = "tfy-aui-chat-draft-spec-preferences";
217
+ var AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY = "tfy-aui-agent-draft-spec-preferences";
218
+ function isObject(value) {
219
+ return typeof value === "object" && value !== null;
220
+ }
221
+ function isMountList(value) {
222
+ return Array.isArray(value) && value.every(isObject);
223
+ }
224
+ function isAgentSpec(value) {
225
+ if (!isObject(value)) return false;
226
+ const model = Reflect.get(value, "model");
227
+ if (!isObject(model) || typeof Reflect.get(model, "name") !== "string") return false;
228
+ const params = Reflect.get(model, "params");
229
+ if (params !== void 0 && !isObject(params)) return false;
230
+ const skills = Reflect.get(value, "skills");
231
+ if (skills !== void 0 && !isMountList(skills)) return false;
232
+ const mcpServers = Reflect.get(value, "mcpServers");
233
+ if (mcpServers !== void 0 && !isMountList(mcpServers)) return false;
234
+ const config = Reflect.get(value, "config");
235
+ return config === void 0 || isObject(config);
236
+ }
237
+ function isStoredDraftSpecPreferences(value) {
238
+ return isObject(value) && Reflect.get(value, "version") === 1 && isAgentSpec(Reflect.get(value, "spec"));
239
+ }
240
+ function storageKeyForKind(kind) {
241
+ return kind === "chat" ? CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY : AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY;
242
+ }
243
+ function selectChatDraftSpecPreferences(spec) {
244
+ return {
245
+ model: spec.model,
246
+ ...spec.skills !== void 0 ? { skills: spec.skills } : {},
247
+ ...spec.mcpServers !== void 0 ? { mcpServers: spec.mcpServers } : {}
248
+ };
249
+ }
250
+ function selectAgentDraftSpecPreferences(spec) {
251
+ return {
252
+ ...selectChatDraftSpecPreferences(spec),
253
+ ...spec.config !== void 0 ? { config: spec.config } : {}
254
+ };
255
+ }
256
+ function selectDraftSpecPreferences(spec, kind) {
257
+ return kind === "chat" ? selectChatDraftSpecPreferences(spec) : selectAgentDraftSpecPreferences(spec);
258
+ }
259
+ function readSandboxEnabled(spec) {
260
+ if (spec.config === void 0) return void 0;
261
+ const sandbox = Reflect.get(spec.config, "sandbox");
262
+ if (!isObject(sandbox)) return void 0;
263
+ const enabled = Reflect.get(sandbox, "enabled");
264
+ return typeof enabled === "boolean" ? enabled : void 0;
265
+ }
266
+ function withCapabilitiesSandbox(spec, sandboxEnabled) {
267
+ if (sandboxEnabled !== false || readSandboxEnabled(spec) === false) return spec;
268
+ const config = {
269
+ ...spec.config,
270
+ sandbox: { ...spec.config?.sandbox, enabled: false }
271
+ };
272
+ return {
273
+ ...spec,
274
+ config
275
+ };
276
+ }
277
+ function readStoredSpec(key) {
278
+ if (typeof window === "undefined") return null;
279
+ try {
280
+ const stored = JSON.parse(window.localStorage.getItem(key) ?? "null");
281
+ return isStoredDraftSpecPreferences(stored) ? stored.spec : null;
282
+ } catch {
283
+ return null;
284
+ }
285
+ }
286
+ function writeStoredSpec(key, spec) {
287
+ if (typeof window === "undefined") return false;
288
+ try {
289
+ const stored = { version: 1, spec };
290
+ window.localStorage.setItem(key, JSON.stringify(stored));
291
+ return true;
292
+ } catch {
293
+ return false;
294
+ }
295
+ }
296
+ function migrateLegacyDraftPreferences() {
297
+ if (typeof window === "undefined") return;
298
+ const legacy = readStoredSpec(DRAFT_SPEC_PREFERENCES_STORAGE_KEY);
299
+ if (legacy == null) return;
300
+ const chatReady = readStoredSpec(CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY) != null || writeStoredSpec(CHAT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY, selectChatDraftSpecPreferences(legacy));
301
+ const agentReady = readStoredSpec(AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY) != null || writeStoredSpec(AGENT_DRAFT_SPEC_PREFERENCES_STORAGE_KEY, selectAgentDraftSpecPreferences(legacy));
302
+ if (!chatReady || !agentReady) return;
303
+ try {
304
+ window.localStorage.removeItem(DRAFT_SPEC_PREFERENCES_STORAGE_KEY);
305
+ } catch {
306
+ }
307
+ }
308
+ function readDraftSpecPreferences(kind) {
309
+ migrateLegacyDraftPreferences();
310
+ const stored = readStoredSpec(storageKeyForKind(kind));
311
+ return stored == null ? null : selectDraftSpecPreferences(stored, kind);
312
+ }
313
+ function writeDraftSpecPreferences(kind, spec) {
314
+ writeStoredSpec(storageKeyForKind(kind), selectDraftSpecPreferences(spec, kind));
315
+ }
316
+
317
+ // src/server/ShellModeContext.tsx
318
+ import { jsx as jsx2 } from "react/jsx-runtime";
319
+ var DEFAULT_AGENT_CONFIG = {
320
+ mode: "AgentLibraryWithComposer"
321
+ };
322
+ var ShellModeContext = createContext2(null);
323
+ var FALLBACK_MUTABLE_SPEC = {
324
+ model: { name: "openai-main/gpt-4.1" }
325
+ };
326
+ function mutableSeedFromConfig(config) {
327
+ if (config.mode === "AgentComposer" || config.mode === "AgentLibraryWithComposer") {
328
+ return config.defaultAgentSpec ?? FALLBACK_MUTABLE_SPEC;
329
+ }
330
+ return FALLBACK_MUTABLE_SPEC;
331
+ }
332
+ function initialMode(config, mutableSeed) {
333
+ switch (config.mode) {
334
+ case "SingleAgent":
335
+ return {
336
+ status: "active",
337
+ isMutable: false,
338
+ isCreateAgent: false,
339
+ agentId: config.name,
340
+ agentName: config.name,
341
+ locked: true
342
+ };
343
+ case "AgentLibrary":
344
+ return { status: "idle" };
345
+ case "AgentComposer":
346
+ case "AgentLibraryWithComposer":
347
+ return {
348
+ status: "active",
349
+ isMutable: true,
350
+ isCreateAgent: false,
351
+ agentSpec: mutableSeed,
352
+ locked: false
353
+ };
354
+ }
355
+ }
356
+ function resolveMutableIsCreateAgent(req) {
357
+ if (req.isCreateAgent !== void 0) return req.isCreateAgent;
358
+ return req.agentId != null || req.agentName != null;
359
+ }
360
+ function libraryAgentId(agent) {
361
+ return agent.agentId ?? agent.name;
362
+ }
363
+ function ShellModeProvider({
364
+ agentConfig = DEFAULT_AGENT_CONFIG,
365
+ initialSettingsOpen = false,
366
+ children
367
+ }) {
368
+ const capabilities = useServerCapabilities();
369
+ const catalog = useOptionalCatalogServer();
370
+ const refreshCapabilities = useOptionalRefreshServerCapabilities();
371
+ const scheduleServer = useOptionalScheduleServer();
372
+ const chatSeedRef = useRef2(
373
+ readDraftSpecPreferences("chat") ?? selectDraftSpecPreferences(mutableSeedFromConfig(agentConfig), "chat")
374
+ );
375
+ const agentSeedRef = useRef2(
376
+ readDraftSpecPreferences("agent") ?? selectDraftSpecPreferences(mutableSeedFromConfig(agentConfig), "agent")
377
+ );
378
+ const isLibraryEnabled = agentConfig.mode === "AgentLibrary" || agentConfig.mode === "AgentLibraryWithComposer";
379
+ const isComposerEnabled = agentConfig.mode === "AgentComposer" || agentConfig.mode === "AgentLibraryWithComposer";
380
+ const isNewChatEnabled = agentConfig.mode !== "AgentLibrary";
381
+ const locked = agentConfig.mode === "SingleAgent";
382
+ const [mode, setMode] = useState2(() => initialMode(agentConfig, chatSeedRef.current));
383
+ const [mutableEpoch, setMutableEpoch] = useState2(0);
384
+ const [clearEpoch, setClearEpoch] = useState2(0);
385
+ const [agentsListEpoch, setAgentsListEpoch] = useState2(0);
386
+ const [settingsOpenState, setSettingsOpenState] = useState2(initialSettingsOpen);
387
+ const [settingsSection, setSettingsSection] = useState2("models");
388
+ const [agentConfigOpenState, setAgentConfigOpenState] = useState2(false);
389
+ const [libraryOpenState, setLibraryOpenState] = useState2(false);
390
+ const [sessionsOpenState, setSessionsOpenState] = useState2(false);
391
+ const [libraryAgentId2, setLibraryAgentId] = useState2(null);
392
+ const [schedulesOpenState, setSchedulesOpenState] = useState2(false);
393
+ const [historyAgentFilter, setHistoryAgentFilter] = useState2(null);
394
+ const [pendingSessionId, setPendingSessionId] = useState2(void 0);
395
+ const settingsEnabled = isSettingsChromeEnabled({ catalog, capabilities });
396
+ const settingsOpen = settingsEnabled && settingsOpenState;
397
+ const schedulesEnabled = scheduleServer != null;
398
+ const schedulesOpen = schedulesEnabled && schedulesOpenState;
399
+ const libraryOpen = isLibraryEnabled && libraryOpenState;
400
+ const sessionsOpen = sessionsOpenState;
401
+ const setSessionsOpen = useCallback2((open) => {
402
+ if (open) {
403
+ setSettingsOpenState(false);
404
+ setAgentConfigOpenState(false);
405
+ setLibraryOpenState(false);
406
+ setLibraryAgentId(null);
407
+ setSchedulesOpenState(false);
408
+ } else {
409
+ replaceSessionShareSearch({ view: null });
410
+ }
411
+ setSessionsOpenState(open);
412
+ }, []);
413
+ const setLibraryOpen = useCallback2(
414
+ (open) => {
415
+ if (!isLibraryEnabled) return;
416
+ if (open) {
417
+ setSettingsOpenState(false);
418
+ setAgentConfigOpenState(false);
419
+ setSessionsOpen(false);
420
+ setSchedulesOpenState(false);
421
+ }
422
+ setLibraryAgentId(null);
423
+ setLibraryOpenState(open);
424
+ },
425
+ [isLibraryEnabled, setSessionsOpen]
426
+ );
427
+ const openLibraryAgent = useCallback2(
428
+ (agentId) => {
429
+ if (!isLibraryEnabled) return;
430
+ setSettingsOpenState(false);
431
+ setAgentConfigOpenState(false);
432
+ setSessionsOpen(false);
433
+ setSchedulesOpenState(false);
434
+ setLibraryOpenState(true);
435
+ setLibraryAgentId(agentId);
436
+ },
437
+ [isLibraryEnabled, setSessionsOpen]
438
+ );
439
+ const closeLibraryAgent = useCallback2(() => {
440
+ setLibraryAgentId(null);
441
+ }, []);
442
+ const setSettingsOpen = useCallback2(
443
+ (open, section) => {
444
+ if (section !== void 0) {
445
+ setSettingsSection(section);
446
+ }
447
+ if (open) {
448
+ setAgentConfigOpenState(false);
449
+ setLibraryOpenState(false);
450
+ setLibraryAgentId(null);
451
+ setSessionsOpen(false);
452
+ setSchedulesOpenState(false);
453
+ }
454
+ setSettingsOpenState(settingsEnabled && open);
455
+ },
456
+ [setSessionsOpen, settingsEnabled]
457
+ );
458
+ const setAgentConfigOpen = useCallback2(
459
+ (open) => {
460
+ if (open) {
461
+ setSettingsOpenState(false);
462
+ setLibraryOpenState(false);
463
+ setLibraryAgentId(null);
464
+ setSessionsOpen(false);
465
+ setSchedulesOpenState(false);
466
+ }
467
+ setAgentConfigOpenState(open);
468
+ },
469
+ [setSessionsOpen]
470
+ );
471
+ const setSchedulesOpen = useCallback2(
472
+ (open) => {
473
+ if (open) {
474
+ setSettingsOpenState(false);
475
+ setAgentConfigOpenState(false);
476
+ setLibraryOpenState(false);
477
+ setLibraryAgentId(null);
478
+ setSessionsOpen(false);
479
+ }
480
+ setSchedulesOpenState(schedulesEnabled && open);
481
+ },
482
+ [schedulesEnabled, setSessionsOpen]
483
+ );
484
+ useEffect2(() => {
485
+ if (!settingsEnabled) {
486
+ setSettingsOpenState(false);
487
+ }
488
+ }, [settingsEnabled]);
489
+ useEffect2(() => {
490
+ if (!schedulesEnabled) {
491
+ setSchedulesOpenState(false);
492
+ }
493
+ }, [schedulesEnabled]);
494
+ const invalidateAgentsList = useCallback2(() => {
495
+ setAgentsListEpoch((n) => n + 1);
496
+ }, []);
497
+ const lockedAgentName = agentConfig.mode === "SingleAgent" ? agentConfig.name : "";
498
+ const effectiveMode = useMemo2(() => {
499
+ if (!locked) return mode;
500
+ return {
501
+ status: "active",
502
+ isMutable: false,
503
+ isCreateAgent: false,
504
+ agentId: lockedAgentName,
505
+ agentName: lockedAgentName,
506
+ locked: true
507
+ };
508
+ }, [locked, lockedAgentName, mode]);
509
+ const agentConfigOpen = effectiveMode.status === "active" && effectiveMode.isMutable && effectiveMode.isCreateAgent && agentConfigOpenState;
510
+ useEffect2(() => {
511
+ if (effectiveMode.status !== "active" || !effectiveMode.isMutable || !effectiveMode.isCreateAgent) {
512
+ setAgentConfigOpenState(false);
513
+ }
514
+ }, [effectiveMode]);
515
+ const listSessionsAgentId = useMemo2(() => {
516
+ if (locked) return lockedAgentName;
517
+ if (!isLibraryEnabled) return void 0;
518
+ return historyAgentFilter ?? void 0;
519
+ }, [locked, lockedAgentName, isLibraryEnabled, historyAgentFilter]);
520
+ const bumpEpoch = useCallback2((isMutable) => {
521
+ if (isMutable) setMutableEpoch((n) => n + 1);
522
+ else setClearEpoch((n) => n + 1);
523
+ }, []);
524
+ const selectLibraryAgent = useCallback2(
525
+ (req) => {
526
+ if (req.isMutable) {
527
+ if (!isComposerEnabled) return;
528
+ setSettingsOpen(false);
529
+ setLibraryOpenState(false);
530
+ setLibraryAgentId(null);
531
+ setSessionsOpen(false);
532
+ setSchedulesOpen(false);
533
+ setPendingSessionId(void 0);
534
+ const isCreateAgent = resolveMutableIsCreateAgent(req);
535
+ const kind = isCreateAgent ? "agent" : "chat";
536
+ setMode({
537
+ status: "active",
538
+ isMutable: true,
539
+ isCreateAgent,
540
+ agentId: req.agentId,
541
+ agentName: req.agentName,
542
+ agentSpec: req.agentSpec ?? (kind === "agent" ? agentSeedRef.current : chatSeedRef.current),
543
+ locked: false
544
+ });
545
+ setAgentConfigOpenState(isCreateAgent);
546
+ bumpEpoch(true);
547
+ return;
548
+ }
549
+ if (!isLibraryEnabled) return;
550
+ const agentName = req.agentName ?? req.agentId;
551
+ if (agentName == null) return;
552
+ setSettingsOpen(false);
553
+ setLibraryOpenState(false);
554
+ setLibraryAgentId(null);
555
+ setSessionsOpen(false);
556
+ setSchedulesOpen(false);
557
+ setPendingSessionId(void 0);
558
+ setAgentConfigOpenState(false);
559
+ setMode({
560
+ status: "active",
561
+ isMutable: false,
562
+ isCreateAgent: false,
563
+ agentId: req.agentId ?? agentName,
564
+ agentName,
565
+ locked: false
566
+ });
567
+ bumpEpoch(false);
568
+ },
569
+ [isComposerEnabled, isLibraryEnabled, bumpEpoch, setSettingsOpen, setSessionsOpen, setSchedulesOpen]
570
+ );
571
+ const bindMutableAgent = useCallback2(
572
+ (req) => {
573
+ if (!isComposerEnabled) return;
574
+ setMode((prev) => {
575
+ if (prev.status !== "active" || !prev.isMutable) return prev;
576
+ return {
577
+ status: "active",
578
+ isMutable: true,
579
+ isCreateAgent: true,
580
+ agentId: req.agentId,
581
+ agentName: req.agentName,
582
+ agentSpec: req.agentSpec,
583
+ locked: false
584
+ };
585
+ });
586
+ },
587
+ [isComposerEnabled]
588
+ );
589
+ const selectAgent = useCallback2(
590
+ (name) => {
591
+ selectLibraryAgent({ isMutable: false, agentId: name, agentName: name });
592
+ },
593
+ [selectLibraryAgent]
594
+ );
595
+ const openDraft = useCallback2(() => {
596
+ if (!isComposerEnabled) return;
597
+ refreshCapabilities?.();
598
+ selectLibraryAgent({ isMutable: true, isCreateAgent: false, agentSpec: chatSeedRef.current });
599
+ }, [isComposerEnabled, refreshCapabilities, selectLibraryAgent]);
600
+ const openAgentBuilder = useCallback2(() => {
601
+ if (!isComposerEnabled) return;
602
+ refreshCapabilities?.();
603
+ selectLibraryAgent({ isMutable: true, isCreateAgent: true, agentSpec: agentSeedRef.current });
604
+ }, [isComposerEnabled, refreshCapabilities, selectLibraryAgent]);
605
+ const sandboxEnabled = capabilities?.sandbox.enabled;
606
+ const rememberDraftSpec = useCallback2(
607
+ (agentSpec, kind = "chat") => {
608
+ const selected = selectDraftSpecPreferences(agentSpec, kind);
609
+ const preferences = kind === "agent" ? withCapabilitiesSandbox(selected, sandboxEnabled) : selected;
610
+ if (kind === "chat") {
611
+ chatSeedRef.current = preferences;
612
+ } else {
613
+ agentSeedRef.current = preferences;
614
+ }
615
+ writeDraftSpecPreferences(kind, preferences);
616
+ },
617
+ [sandboxEnabled]
618
+ );
619
+ const openHistorySession = useCallback2(
620
+ ({
621
+ sessionId,
622
+ agentName,
623
+ isMutable: isMutableOpt,
624
+ isCreateAgent: isCreateAgentOpt
625
+ }) => {
626
+ setSettingsOpen(false);
627
+ setLibraryOpenState(false);
628
+ setLibraryAgentId(null);
629
+ setSessionsOpen(false);
630
+ setSchedulesOpen(false);
631
+ setPendingSessionId(sessionId);
632
+ const isMutable = isMutableOpt ?? agentName == null;
633
+ if (isMutable) {
634
+ if (!isComposerEnabled) return;
635
+ const isCreateAgent = isCreateAgentOpt === true;
636
+ setMode({
637
+ status: "active",
638
+ isMutable: true,
639
+ isCreateAgent,
640
+ agentSpec: isCreateAgent ? agentSeedRef.current : chatSeedRef.current,
641
+ locked: false
642
+ });
643
+ setAgentConfigOpenState(isCreateAgent);
644
+ bumpEpoch(true);
645
+ return;
646
+ }
647
+ if (locked) {
648
+ if (agentName == null || lockedAgentName !== agentName) return;
649
+ } else if (!isLibraryEnabled) {
650
+ return;
651
+ }
652
+ setAgentConfigOpenState(false);
653
+ setMode({
654
+ status: "active",
655
+ isMutable: false,
656
+ isCreateAgent: false,
657
+ locked: false,
658
+ ...agentName != null ? { agentId: agentName, agentName } : {}
659
+ });
660
+ bumpEpoch(false);
661
+ },
662
+ [
663
+ isLibraryEnabled,
664
+ isComposerEnabled,
665
+ locked,
666
+ lockedAgentName,
667
+ bumpEpoch,
668
+ setSettingsOpen,
669
+ setSessionsOpen,
670
+ setSchedulesOpen
671
+ ]
672
+ );
673
+ const clearChat = useCallback2(() => {
674
+ if (effectiveMode.status === "idle") return;
675
+ setPendingSessionId(void 0);
676
+ if (effectiveMode.isMutable) {
677
+ const kind = effectiveMode.isCreateAgent ? "agent" : "chat";
678
+ setMode({
679
+ status: "active",
680
+ isMutable: true,
681
+ isCreateAgent: effectiveMode.isCreateAgent,
682
+ agentId: effectiveMode.agentId,
683
+ agentName: effectiveMode.agentName,
684
+ agentSpec: effectiveMode.agentSpec ?? (kind === "agent" ? agentSeedRef.current : chatSeedRef.current),
685
+ locked: false
686
+ });
687
+ setAgentConfigOpenState(effectiveMode.isCreateAgent);
688
+ bumpEpoch(true);
689
+ return;
690
+ }
691
+ bumpEpoch(false);
692
+ }, [effectiveMode, bumpEpoch]);
693
+ const openLibraryHome = useCallback2(() => {
694
+ if (!isLibraryEnabled || isComposerEnabled) return;
695
+ setPendingSessionId(void 0);
696
+ setSettingsOpen(false);
697
+ setLibraryOpenState(false);
698
+ setLibraryAgentId(null);
699
+ setSchedulesOpen(false);
700
+ setMode({ status: "idle" });
701
+ bumpEpoch(false);
702
+ }, [isLibraryEnabled, isComposerEnabled, setSettingsOpen, setSchedulesOpen, bumpEpoch]);
703
+ const runtimeKey = useMemo2(() => {
704
+ if (effectiveMode.status === "idle") return "idle";
705
+ if (effectiveMode.isMutable) {
706
+ return `mut:${pendingSessionId ?? ""}:${mutableEpoch}`;
707
+ }
708
+ const id = effectiveMode.agentId ?? effectiveMode.agentName ?? "";
709
+ return `immut:${id}:${pendingSessionId ?? ""}:${clearEpoch}`;
710
+ }, [effectiveMode, mutableEpoch, clearEpoch, pendingSessionId]);
711
+ const value = useMemo2(
712
+ () => ({
713
+ mode: effectiveMode,
714
+ agentConfigMode: agentConfig.mode,
715
+ isLibraryEnabled,
716
+ isComposerEnabled,
717
+ isNewChatEnabled,
718
+ settingsOpen,
719
+ settingsSection,
720
+ setSettingsOpen,
721
+ agentConfigOpen,
722
+ setAgentConfigOpen,
723
+ libraryOpen,
724
+ libraryAgentId: libraryAgentId2,
725
+ setLibraryAgentId,
726
+ setLibraryOpen,
727
+ sessionsOpen,
728
+ setSessionsOpen,
729
+ openLibraryAgent,
730
+ closeLibraryAgent,
731
+ schedulesOpen,
732
+ setSchedulesOpen,
733
+ selectLibraryAgent,
734
+ bindMutableAgent,
735
+ selectAgent,
736
+ openDraft,
737
+ openAgentBuilder,
738
+ rememberDraftSpec,
739
+ openHistorySession,
740
+ clearChat,
741
+ openLibraryHome,
742
+ runtimeKey,
743
+ historyAgentFilter,
744
+ setHistoryAgentFilter,
745
+ listSessionsAgentId,
746
+ pendingSessionId,
747
+ agentsListEpoch,
748
+ invalidateAgentsList
749
+ }),
750
+ [
751
+ effectiveMode,
752
+ agentConfig.mode,
753
+ isLibraryEnabled,
754
+ isComposerEnabled,
755
+ isNewChatEnabled,
756
+ settingsOpen,
757
+ settingsSection,
758
+ setSettingsOpen,
759
+ agentConfigOpen,
760
+ setAgentConfigOpen,
761
+ libraryOpen,
762
+ libraryAgentId2,
763
+ setLibraryOpen,
764
+ sessionsOpen,
765
+ setSessionsOpen,
766
+ openLibraryAgent,
767
+ closeLibraryAgent,
768
+ schedulesOpen,
769
+ setSchedulesOpen,
770
+ selectLibraryAgent,
771
+ bindMutableAgent,
772
+ selectAgent,
773
+ openDraft,
774
+ openAgentBuilder,
775
+ rememberDraftSpec,
776
+ openHistorySession,
777
+ clearChat,
778
+ openLibraryHome,
779
+ runtimeKey,
780
+ historyAgentFilter,
781
+ listSessionsAgentId,
782
+ pendingSessionId,
783
+ agentsListEpoch,
784
+ invalidateAgentsList
785
+ ]
786
+ );
787
+ return /* @__PURE__ */ jsx2(ShellModeContext.Provider, { value, children });
788
+ }
789
+ function useShellMode() {
790
+ const ctx = useContext2(ShellModeContext);
791
+ if (ctx == null) {
792
+ throw new Error("useShellMode must be used within a ShellModeProvider.");
793
+ }
794
+ return ctx;
795
+ }
796
+ function useOptionalShellMode() {
797
+ return useContext2(ShellModeContext);
798
+ }
799
+ function shellIsMutable(mode) {
800
+ return mode.status === "active" && mode.isMutable;
801
+ }
802
+ function shellIsCreateAgent(mode) {
803
+ return mode.status === "active" && mode.isMutable && mode.isCreateAgent;
804
+ }
805
+
806
+ export {
807
+ ServerProvider,
808
+ useServer,
809
+ useOptionalServer,
810
+ useServerCapabilities,
811
+ useOptionalRefreshServerCapabilities,
812
+ useCatalogServer,
813
+ useOptionalCatalogServer,
814
+ useAgentSessionsServer,
815
+ useOptionalAgentSessionsServer,
816
+ useAgentMetricsServer,
817
+ useOptionalAgentMetricsServer,
818
+ useScheduleServer,
819
+ useOptionalScheduleServer,
820
+ SESSION_CUSTOM_RANGE_MAX_DAYS,
821
+ defaultSessionTimeRange,
822
+ sessionTimeRangeFromCreatedAt,
823
+ resolveSessionTimeRange,
824
+ readSessionShareSearch,
825
+ libraryAgentTabFromSearch,
826
+ writeSessionShareSearch,
827
+ buildAgentSessionShareUrl,
828
+ SESSION_SHARE_CHANGE_EVENT,
829
+ replaceSessionShareSearch,
830
+ withCapabilitiesSandbox,
831
+ isSettingsChromeEnabled,
832
+ DEFAULT_AGENT_CONFIG,
833
+ libraryAgentId,
834
+ ShellModeProvider,
835
+ useShellMode,
836
+ useOptionalShellMode,
837
+ shellIsMutable,
838
+ shellIsCreateAgent
839
+ };
840
+ //# sourceMappingURL=chunk-U7KURWW3.js.map