@makinbakin/sdk 0.0.0-bootstrap.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +107 -0
  2. package/_internal/app/components/agent-avatar.d.ts +11 -0
  3. package/_internal/app/components/agent-filter.d.ts +8 -0
  4. package/_internal/app/components/agent-select.d.ts +15 -0
  5. package/_internal/app/components/agent-status.d.ts +8 -0
  6. package/_internal/app/components/bakin-drawer.d.ts +23 -0
  7. package/_internal/app/components/color-picker.d.ts +7 -0
  8. package/_internal/app/components/empty-state.d.ts +10 -0
  9. package/_internal/app/components/error-banner.d.ts +6 -0
  10. package/_internal/app/components/error-state.d.ts +8 -0
  11. package/_internal/app/components/facet-filter.d.ts +17 -0
  12. package/_internal/app/components/integrated-brainstorm/collapsed-header.d.ts +14 -0
  13. package/_internal/app/components/integrated-brainstorm/empty-state.d.ts +5 -0
  14. package/_internal/app/components/integrated-brainstorm/index.d.ts +3 -0
  15. package/_internal/app/components/integrated-brainstorm/input-row.d.ts +16 -0
  16. package/_internal/app/components/integrated-brainstorm/message-list.d.ts +8 -0
  17. package/_internal/app/components/integrated-brainstorm/thinking-indicator.d.ts +19 -0
  18. package/_internal/app/components/integrated-brainstorm/types.d.ts +61 -0
  19. package/_internal/app/components/integrated-brainstorm/use-auto-grow.d.ts +6 -0
  20. package/_internal/app/components/integrated-brainstorm/use-brainstorm-state.d.ts +21 -0
  21. package/_internal/app/components/markdown-content.d.ts +3 -0
  22. package/_internal/app/components/markdown-editor.d.ts +11 -0
  23. package/_internal/app/components/model-select.d.ts +9 -0
  24. package/_internal/app/components/page-layout.d.ts +9 -0
  25. package/_internal/app/components/plugin-header.d.ts +16 -0
  26. package/_internal/app/components/plugin-settings-renderer.d.ts +9 -0
  27. package/_internal/app/components/sortable-head.d.ts +13 -0
  28. package/_internal/app/components/ui/alert.d.ts +10 -0
  29. package/_internal/app/components/ui/avatar.d.ts +11 -0
  30. package/_internal/app/components/ui/badge.d.ts +7 -0
  31. package/_internal/app/components/ui/button.d.ts +8 -0
  32. package/_internal/app/components/ui/card.d.ts +11 -0
  33. package/_internal/app/components/ui/checkbox.d.ts +3 -0
  34. package/_internal/app/components/ui/collapsible.d.ts +5 -0
  35. package/_internal/app/components/ui/command.d.ts +19 -0
  36. package/_internal/app/components/ui/dialog.d.ts +17 -0
  37. package/_internal/app/components/ui/dropdown-menu.d.ts +29 -0
  38. package/_internal/app/components/ui/form.d.ts +23 -0
  39. package/_internal/app/components/ui/input-group.d.ts +18 -0
  40. package/_internal/app/components/ui/input.d.ts +3 -0
  41. package/_internal/app/components/ui/label.d.ts +3 -0
  42. package/_internal/app/components/ui/popover.d.ts +9 -0
  43. package/_internal/app/components/ui/progress.d.ts +7 -0
  44. package/_internal/app/components/ui/select.d.ts +15 -0
  45. package/_internal/app/components/ui/separator.d.ts +3 -0
  46. package/_internal/app/components/ui/sheet.d.ts +14 -0
  47. package/_internal/app/components/ui/skeleton.d.ts +2 -0
  48. package/_internal/app/components/ui/switch.d.ts +5 -0
  49. package/_internal/app/components/ui/table.d.ts +10 -0
  50. package/_internal/app/components/ui/tabs.d.ts +10 -0
  51. package/_internal/app/components/ui/textarea.d.ts +3 -0
  52. package/_internal/app/components/ui/tooltip.d.ts +6 -0
  53. package/_internal/app/components/underline-tabs.d.ts +15 -0
  54. package/_internal/app/hooks/use-assets.d.ts +25 -0
  55. package/_internal/app/hooks/use-content-store.d.ts +36 -0
  56. package/_internal/app/hooks/use-debug.d.ts +1 -0
  57. package/_internal/app/hooks/use-form-guard.d.ts +5 -0
  58. package/_internal/app/hooks/use-query-state.d.ts +14 -0
  59. package/_internal/app/hooks/use-runtime-status.d.ts +12 -0
  60. package/_internal/app/hooks/use-schedule.d.ts +63 -0
  61. package/_internal/app/hooks/use-search.d.ts +65 -0
  62. package/_internal/app/hooks/use-sidebar.d.ts +4 -0
  63. package/_internal/app/hooks/use-sse.d.ts +1 -0
  64. package/_internal/app/hooks/use-toast.d.ts +16 -0
  65. package/_internal/app/hooks/use-vertical-resize.d.ts +22 -0
  66. package/_internal/app/lib/browser-notify.d.ts +5 -0
  67. package/_internal/app/lib/map-audit-message.d.ts +7 -0
  68. package/_internal/app/lib/utils.d.ts +2 -0
  69. package/_internal/app/types/index.d.ts +126 -0
  70. package/_internal/core/adapters/runtime/capabilities.d.ts +2 -0
  71. package/_internal/core/adapters/runtime/concepts.d.ts +458 -0
  72. package/_internal/core/adapters/runtime/helpers.d.ts +5 -0
  73. package/_internal/core/adapters/runtime/index.d.ts +5 -0
  74. package/_internal/core/adapters/shared.d.ts +37 -0
  75. package/_internal/core/docs/index.d.ts +2 -0
  76. package/_internal/core/docs/metadata.d.ts +92 -0
  77. package/_internal/core/docs/route.d.ts +9 -0
  78. package/_internal/core/format.d.ts +6 -0
  79. package/_internal/core/openapi/errors.d.ts +29 -0
  80. package/_internal/core/openapi/zod-to-openapi.d.ts +14 -0
  81. package/_internal/core/plugin-types.d.ts +849 -0
  82. package/_internal/core/routing/define.d.ts +34 -0
  83. package/_internal/core/routing/dispatcher.d.ts +44 -0
  84. package/_internal/core/routing/index.d.ts +15 -0
  85. package/_internal/core/routing/operation-id.d.ts +9 -0
  86. package/_internal/core/routing/registry.d.ts +52 -0
  87. package/_internal/core/routing/search-route.d.ts +26 -0
  88. package/_internal/core/routing/types.d.ts +123 -0
  89. package/_internal/plugins/team/hooks/use-agent-store.d.ts +49 -0
  90. package/_internal/plugins/team/types.d.ts +131 -0
  91. package/_internal/plugins/workflows/hooks/channel-icon.d.ts +6 -0
  92. package/_internal/plugins/workflows/hooks/use-notification-channels.d.ts +13 -0
  93. package/_internal/plugins/workflows/lib/notification-channel-registry.d.ts +26 -0
  94. package/components/index.d.ts +33 -0
  95. package/components/index.js +39522 -0
  96. package/hooks/index.d.ts +25 -0
  97. package/hooks/index.js +1738 -0
  98. package/hooks/router.d.ts +38 -0
  99. package/index.d.ts +27 -0
  100. package/index.js +13917 -0
  101. package/metadata/index.d.ts +16 -0
  102. package/metadata/index.js +31 -0
  103. package/package.json +88 -0
  104. package/register.d.ts +103 -0
  105. package/routing/index.d.ts +11 -0
  106. package/routing/index.js +13721 -0
  107. package/slots/index.d.ts +55 -0
  108. package/slots/index.js +92 -0
  109. package/types/index.d.ts +840 -0
  110. package/types/index.js +1 -0
  111. package/ui/index.d.ts +34 -0
  112. package/ui/index.js +28713 -0
  113. package/utils/index.d.ts +9 -0
  114. package/utils/index.js +1832 -0
package/hooks/index.js ADDED
@@ -0,0 +1,1738 @@
1
+ // @bun
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
12
+ var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
20
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
21
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
+ for (let key of __getOwnPropNames(mod))
23
+ if (!__hasOwnProp.call(to, key))
24
+ __defProp(to, key, {
25
+ get: __accessProp.bind(mod, key),
26
+ enumerable: true
27
+ });
28
+ if (canCache)
29
+ cache.set(mod, to);
30
+ return to;
31
+ };
32
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
33
+
34
+ // node_modules/.bun/use-sync-external-store@1.6.0+b1ab299f0a400331/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
35
+ import * as React2 from "react";
36
+ var require_use_sync_external_store_shim_development = __commonJS((exports) => {
37
+ (function() {
38
+ function is(x, y) {
39
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
40
+ }
41
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
42
+ didWarnOld18Alpha || React2.startTransition === undefined || (didWarnOld18Alpha = true, console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
43
+ var value = getSnapshot();
44
+ if (!didWarnUncachedGetSnapshot) {
45
+ var cachedValue = getSnapshot();
46
+ objectIs(value, cachedValue) || (console.error("The result of getSnapshot should be cached to avoid an infinite loop"), didWarnUncachedGetSnapshot = true);
47
+ }
48
+ cachedValue = useState9({
49
+ inst: { value, getSnapshot }
50
+ });
51
+ var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
52
+ useLayoutEffect2(function() {
53
+ inst.value = value;
54
+ inst.getSnapshot = getSnapshot;
55
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
56
+ }, [subscribe, value, getSnapshot]);
57
+ useEffect11(function() {
58
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
59
+ return subscribe(function() {
60
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
61
+ });
62
+ }, [subscribe]);
63
+ useDebugValue2(value);
64
+ return value;
65
+ }
66
+ function checkIfSnapshotChanged(inst) {
67
+ var latestGetSnapshot = inst.getSnapshot;
68
+ inst = inst.value;
69
+ try {
70
+ var nextValue = latestGetSnapshot();
71
+ return !objectIs(inst, nextValue);
72
+ } catch (error) {
73
+ return true;
74
+ }
75
+ }
76
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
77
+ return getSnapshot();
78
+ }
79
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
80
+ var objectIs = typeof Object.is === "function" ? Object.is : is, useState9 = React2.useState, useEffect11 = React2.useEffect, useLayoutEffect2 = React2.useLayoutEffect, useDebugValue2 = React2.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = typeof window === "undefined" || typeof window.document === "undefined" || typeof window.document.createElement === "undefined" ? useSyncExternalStore$1 : useSyncExternalStore$2;
81
+ exports.useSyncExternalStore = React2.useSyncExternalStore !== undefined ? React2.useSyncExternalStore : shim;
82
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
83
+ })();
84
+ });
85
+
86
+ // node_modules/.bun/use-sync-external-store@1.6.0+b1ab299f0a400331/node_modules/use-sync-external-store/shim/index.js
87
+ var require_shim = __commonJS((exports, module) => {
88
+ if (false) {} else {
89
+ module.exports = require_use_sync_external_store_shim_development();
90
+ }
91
+ });
92
+
93
+ // node_modules/.bun/use-sync-external-store@1.6.0+b1ab299f0a400331/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
94
+ import * as React3 from "react";
95
+ var require_with_selector_development = __commonJS((exports) => {
96
+ (function() {
97
+ function is(x, y) {
98
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
99
+ }
100
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
101
+ var shim = require_shim(), objectIs = typeof Object.is === "function" ? Object.is : is, useSyncExternalStore = shim.useSyncExternalStore, useRef8 = React3.useRef, useEffect11 = React3.useEffect, useMemo3 = React3.useMemo, useDebugValue2 = React3.useDebugValue;
102
+ exports.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
103
+ var instRef = useRef8(null);
104
+ if (instRef.current === null) {
105
+ var inst = { hasValue: false, value: null };
106
+ instRef.current = inst;
107
+ } else
108
+ inst = instRef.current;
109
+ instRef = useMemo3(function() {
110
+ function memoizedSelector(nextSnapshot) {
111
+ if (!hasMemo) {
112
+ hasMemo = true;
113
+ memoizedSnapshot = nextSnapshot;
114
+ nextSnapshot = selector(nextSnapshot);
115
+ if (isEqual !== undefined && inst.hasValue) {
116
+ var currentSelection = inst.value;
117
+ if (isEqual(currentSelection, nextSnapshot))
118
+ return memoizedSelection = currentSelection;
119
+ }
120
+ return memoizedSelection = nextSnapshot;
121
+ }
122
+ currentSelection = memoizedSelection;
123
+ if (objectIs(memoizedSnapshot, nextSnapshot))
124
+ return currentSelection;
125
+ var nextSelection = selector(nextSnapshot);
126
+ if (isEqual !== undefined && isEqual(currentSelection, nextSelection))
127
+ return memoizedSnapshot = nextSnapshot, currentSelection;
128
+ memoizedSnapshot = nextSnapshot;
129
+ return memoizedSelection = nextSelection;
130
+ }
131
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
132
+ return [
133
+ function() {
134
+ return memoizedSelector(getSnapshot());
135
+ },
136
+ maybeGetServerSnapshot === null ? undefined : function() {
137
+ return memoizedSelector(maybeGetServerSnapshot());
138
+ }
139
+ ];
140
+ }, [getSnapshot, getServerSnapshot, selector, isEqual]);
141
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
142
+ useEffect11(function() {
143
+ inst.hasValue = true;
144
+ inst.value = value;
145
+ }, [value]);
146
+ useDebugValue2(value);
147
+ return value;
148
+ };
149
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
150
+ })();
151
+ });
152
+
153
+ // node_modules/.bun/use-sync-external-store@1.6.0+b1ab299f0a400331/node_modules/use-sync-external-store/shim/with-selector.js
154
+ var require_with_selector = __commonJS((exports, module) => {
155
+ if (false) {} else {
156
+ module.exports = require_with_selector_development();
157
+ }
158
+ });
159
+
160
+ // src/hooks/use-assets.ts
161
+ import { useState, useEffect, useCallback, useRef } from "react";
162
+ "use client";
163
+ function useAssets(options = {}) {
164
+ const [assets, setAssets] = useState([]);
165
+ const [total, setTotal] = useState(0);
166
+ const [loading, setLoading] = useState(true);
167
+ const optionsRef = useRef(options);
168
+ optionsRef.current = options;
169
+ const fetchAssets = useCallback(async () => {
170
+ const params = new URLSearchParams;
171
+ const opts = optionsRef.current;
172
+ if (opts.type && opts.type !== "all")
173
+ params.set("type", opts.type);
174
+ if (opts.agent)
175
+ params.set("agent", opts.agent);
176
+ if (opts.taskId)
177
+ params.set("taskId", opts.taskId);
178
+ if (opts.tag)
179
+ params.set("tag", opts.tag);
180
+ if (opts.limit)
181
+ params.set("limit", String(opts.limit));
182
+ if (opts.offset)
183
+ params.set("offset", String(opts.offset));
184
+ try {
185
+ const res = await fetch(`/api/plugins/assets/?${params}`);
186
+ if (res.ok) {
187
+ const data = await res.json();
188
+ setAssets(data.assets || []);
189
+ setTotal(data.total ?? data.count ?? 0);
190
+ }
191
+ } catch {} finally {
192
+ setLoading(false);
193
+ }
194
+ }, []);
195
+ useEffect(() => {
196
+ fetchAssets();
197
+ }, [fetchAssets, options.type, options.agent, options.taskId, options.tag, options.limit, options.offset]);
198
+ useEffect(() => {
199
+ const es = new EventSource("/api/events");
200
+ const handler = (event) => {
201
+ try {
202
+ const data = JSON.parse(event.data);
203
+ if (data.file?.startsWith("assets/") || data.event?.startsWith("asset.")) {
204
+ fetchAssets();
205
+ }
206
+ } catch {}
207
+ };
208
+ es.addEventListener("message", handler);
209
+ return () => {
210
+ es.removeEventListener("message", handler);
211
+ es.close();
212
+ };
213
+ }, [fetchAssets]);
214
+ const deleteAsset = useCallback(async (filename) => {
215
+ try {
216
+ const res = await fetch(`/api/plugins/assets?filename=${encodeURIComponent(filename)}`, {
217
+ method: "DELETE"
218
+ });
219
+ if (res.ok) {
220
+ setAssets((prev) => prev.filter((a) => a.filename !== filename));
221
+ return true;
222
+ }
223
+ } catch {}
224
+ return false;
225
+ }, []);
226
+ return { assets, total, loading, refresh: fetchAssets, deleteAsset };
227
+ }
228
+ function useTrash() {
229
+ const [items, setItems] = useState([]);
230
+ const [loading, setLoading] = useState(true);
231
+ const fetchTrash = useCallback(async () => {
232
+ try {
233
+ const res = await fetch("/api/plugins/assets/trash");
234
+ if (res.ok) {
235
+ const data = await res.json();
236
+ setItems(data.assets || []);
237
+ }
238
+ } catch {} finally {
239
+ setLoading(false);
240
+ }
241
+ }, []);
242
+ useEffect(() => {
243
+ fetchTrash();
244
+ }, [fetchTrash]);
245
+ useEffect(() => {
246
+ const es = new EventSource("/api/events");
247
+ const handler = (event) => {
248
+ try {
249
+ const data = JSON.parse(event.data);
250
+ if (data.file?.includes(".trash/") || data.event?.startsWith("asset.")) {
251
+ fetchTrash();
252
+ }
253
+ } catch {}
254
+ };
255
+ es.addEventListener("message", handler);
256
+ return () => {
257
+ es.removeEventListener("message", handler);
258
+ es.close();
259
+ };
260
+ }, [fetchTrash]);
261
+ const restoreAsset = useCallback(async (filename) => {
262
+ try {
263
+ const res = await fetch(`/api/plugins/assets/trash/${encodeURIComponent(filename)}/restore`, {
264
+ method: "POST"
265
+ });
266
+ if (res.ok) {
267
+ setItems((prev) => prev.filter((i) => i.filename !== filename));
268
+ return true;
269
+ }
270
+ } catch {}
271
+ return false;
272
+ }, []);
273
+ const permanentDeleteAsset = useCallback(async (filename) => {
274
+ try {
275
+ const res = await fetch(`/api/plugins/assets/trash/${encodeURIComponent(filename)}`, {
276
+ method: "DELETE"
277
+ });
278
+ if (res.ok) {
279
+ setItems((prev) => prev.filter((i) => i.filename !== filename));
280
+ return true;
281
+ }
282
+ } catch {}
283
+ return false;
284
+ }, []);
285
+ const emptyTrash = useCallback(async () => {
286
+ try {
287
+ const res = await fetch("/api/plugins/assets/trash", { method: "DELETE" });
288
+ if (res.ok) {
289
+ setItems([]);
290
+ return true;
291
+ }
292
+ } catch {}
293
+ return false;
294
+ }, []);
295
+ return { items, loading, refresh: fetchTrash, restoreAsset, permanentDeleteAsset, emptyTrash };
296
+ }
297
+ // node_modules/.bun/zustand@5.0.12+10f197a4cef36846/node_modules/zustand/esm/vanilla.mjs
298
+ var createStoreImpl = (createState) => {
299
+ let state;
300
+ const listeners = /* @__PURE__ */ new Set;
301
+ const setState = (partial, replace) => {
302
+ const nextState = typeof partial === "function" ? partial(state) : partial;
303
+ if (!Object.is(nextState, state)) {
304
+ const previousState = state;
305
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
306
+ listeners.forEach((listener) => listener(state, previousState));
307
+ }
308
+ };
309
+ const getState = () => state;
310
+ const getInitialState = () => initialState;
311
+ const subscribe = (listener) => {
312
+ listeners.add(listener);
313
+ return () => listeners.delete(listener);
314
+ };
315
+ const api = { setState, getState, getInitialState, subscribe };
316
+ const initialState = state = createState(setState, getState, api);
317
+ return api;
318
+ };
319
+ var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
320
+
321
+ // node_modules/.bun/zustand@5.0.12+10f197a4cef36846/node_modules/zustand/esm/react.mjs
322
+ import React from "react";
323
+ var identity = (arg) => arg;
324
+ function useStore(api, selector = identity) {
325
+ const slice = React.useSyncExternalStore(api.subscribe, React.useCallback(() => selector(api.getState()), [api, selector]), React.useCallback(() => selector(api.getInitialState()), [api, selector]));
326
+ React.useDebugValue(slice);
327
+ return slice;
328
+ }
329
+ var createImpl = (createState) => {
330
+ const api = createStore(createState);
331
+ const useBoundStore = (selector) => useStore(api, selector);
332
+ Object.assign(useBoundStore, api);
333
+ return useBoundStore;
334
+ };
335
+ var create = (createState) => createState ? createImpl(createState) : createImpl;
336
+
337
+ // src/lib/map-audit-message.ts
338
+ function mapAuditMessage(event, data) {
339
+ switch (event) {
340
+ case "task.dispatched":
341
+ return `Dispatched: ${data.title}`;
342
+ case "task.triaged":
343
+ return `Triaged: ${data.title}`;
344
+ case "task.created":
345
+ return `Created task: ${data.title}`;
346
+ case "task.deleted":
347
+ return `Deleted task: ${data.title}`;
348
+ case "task.moved":
349
+ return `Moved "${data.title}" \u2192 ${data.to}`;
350
+ case "task.assigned":
351
+ return `Assigned "${data.title}" to ${data.assignee}`;
352
+ case "task.blocked":
353
+ return `Blocked: ${data.title} \u2014 ${data.reason || "no reason"}`;
354
+ case "task.updated":
355
+ return `Updated: ${data.title}`;
356
+ case "system.init":
357
+ return "Bakin started";
358
+ case "system.dispatch_error":
359
+ return `Dispatch failed: ${data.error || "unknown error"}`;
360
+ case "workflow.step_dispatched":
361
+ return `Step "${data.label || "unknown"}" dispatched to ${data.agent || "agent"}`;
362
+ case "workflow.step_complete":
363
+ return `Step "${data.label || "unknown"}" completed`;
364
+ case "workflow.gate_reached":
365
+ return `Awaiting approval: ${data.label || "gate"}`;
366
+ case "workflow.gate_approved":
367
+ return `Approved: ${data.label || "gate"}`;
368
+ case "workflow.gate_rejected":
369
+ return `Rejected: ${data.label || "gate"}${data.reason ? ` \u2014 ${data.reason}` : ""}`;
370
+ case "workflow.complete":
371
+ return `Workflow complete${data.workflowId ? ` (${data.workflowId})` : ""}`;
372
+ default: {
373
+ if (event.startsWith("exec.")) {
374
+ const suffix = event.endsWith(".fail") ? " (failed)" : event.endsWith(".error") ? " (error)" : "";
375
+ if (data.label)
376
+ return `${data.label}${suffix}`;
377
+ const toolName = event.replace(/^exec\./, "").replace(/\.(ok|fail|error)$/, "");
378
+ return humanizeExecName(toolName) + suffix;
379
+ }
380
+ return event;
381
+ }
382
+ }
383
+ }
384
+ function humanizeExecName(name) {
385
+ const stripped = name.replace(/^bakin_exec_/, "");
386
+ const words = stripped.split("_");
387
+ if (words.length === 0)
388
+ return name;
389
+ words[0] = words[0].charAt(0).toUpperCase() + words[0].slice(1);
390
+ return words.join(" ");
391
+ }
392
+ function isNoisyEvent(evt) {
393
+ if (evt.agent === "system" && evt.message.startsWith("Dispatch failed"))
394
+ return true;
395
+ return false;
396
+ }
397
+
398
+ // src/hooks/use-content-store.ts
399
+ var useContentStore = create((set, get) => ({
400
+ files: {},
401
+ heartbeats: {},
402
+ connected: false,
403
+ loading: true,
404
+ auditEntries: [],
405
+ activityEvents: [],
406
+ sseConnected: false,
407
+ taskboardVersion: 0,
408
+ debug: false,
409
+ reindexProgress: {},
410
+ setFiles: (files) => set({ files }),
411
+ updateFile: (key, content) => set((state) => ({ files: { ...state.files, [key]: content } })),
412
+ setHeartbeats: (heartbeats) => set({ heartbeats }),
413
+ setConnected: (connected) => set({ connected }),
414
+ appendAuditEntry: (entry) => set((state) => ({ auditEntries: [...state.auditEntries, entry] })),
415
+ appendActivityEvent: (event) => set((state) => {
416
+ if (isNoisyEvent(event))
417
+ return state;
418
+ if (state.activityEvents.some((e) => e.id === event.id))
419
+ return state;
420
+ return { activityEvents: [event, ...state.activityEvents].slice(0, 100) };
421
+ }),
422
+ setActivityEvents: (events) => set({ activityEvents: events.filter((e) => !isNoisyEvent(e)).slice(0, 100) }),
423
+ setSseConnected: (connected) => set({ sseConnected: connected }),
424
+ bumpTaskboard: () => set((state) => ({ taskboardVersion: state.taskboardVersion + 1 })),
425
+ setDebug: (debug) => {
426
+ set({ debug });
427
+ try {
428
+ localStorage.setItem("bakin-debug", String(debug));
429
+ } catch {}
430
+ },
431
+ toggleDebug: () => {
432
+ const next = !get().debug;
433
+ set({ debug: next });
434
+ try {
435
+ localStorage.setItem("bakin-debug", String(next));
436
+ } catch {}
437
+ },
438
+ setReindexProgress: (table, indexed, done) => set((state) => ({
439
+ reindexProgress: { ...state.reindexProgress, [table]: { indexed, done } }
440
+ })),
441
+ clearReindexProgress: () => set({ reindexProgress: {} }),
442
+ initialize: async () => {
443
+ try {
444
+ if (localStorage.getItem("bakin-debug") === "true")
445
+ set({ debug: true });
446
+ } catch {}
447
+ try {
448
+ const [stateRes, healthRes, activityRes] = await Promise.all([
449
+ fetch("/api/state"),
450
+ fetch("/api/agents/health"),
451
+ fetch("/api/activity")
452
+ ]);
453
+ if (stateRes.ok) {
454
+ const files = await stateRes.json();
455
+ set({ files });
456
+ }
457
+ if (healthRes.ok) {
458
+ const heartbeats = await healthRes.json();
459
+ set({ heartbeats });
460
+ }
461
+ if (activityRes.ok) {
462
+ const data = await activityRes.json();
463
+ if (data?.events) {
464
+ get().setActivityEvents(data.events);
465
+ }
466
+ }
467
+ } catch {} finally {
468
+ set({ loading: false });
469
+ }
470
+ }
471
+ }));
472
+ // src/hooks/use-debug.ts
473
+ "use client";
474
+ function useDebug() {
475
+ const debug = useContentStore((s) => s.debug);
476
+ const toggleDebug = useContentStore((s) => s.toggleDebug);
477
+ return [debug, toggleDebug];
478
+ }
479
+ // src/hooks/use-form-guard.ts
480
+ import { useEffect as useEffect2 } from "react";
481
+ "use client";
482
+ function useFormGuard(isDirty) {
483
+ useEffect2(() => {
484
+ if (!isDirty)
485
+ return;
486
+ const handler = (e) => {
487
+ e.preventDefault();
488
+ };
489
+ window.addEventListener("beforeunload", handler);
490
+ return () => window.removeEventListener("beforeunload", handler);
491
+ }, [isDirty]);
492
+ }
493
+ // src/hooks/use-runtime-status.ts
494
+ import { useState as useState2, useEffect as useEffect3, useCallback as useCallback2 } from "react";
495
+ "use client";
496
+ function useRuntimeStatus() {
497
+ const [restartNeeded, setRestartNeeded] = useState2(false);
498
+ const [restarting, setRestarting] = useState2(false);
499
+ useEffect3(() => {
500
+ fetch("/api/plugins/models/runtime/status").then((r) => {
501
+ if (!r.ok)
502
+ throw new Error(`Runtime status: ${r.status}`);
503
+ return r.json();
504
+ }).then((data) => {
505
+ if (data?.restartNeeded)
506
+ setRestartNeeded(true);
507
+ }).catch((e) => console.error("Failed to fetch runtime status:", e));
508
+ }, []);
509
+ const restart = useCallback2(async () => {
510
+ setRestarting(true);
511
+ try {
512
+ const res = await fetch("/api/plugins/models/runtime/restart", { method: "POST" });
513
+ if (res.ok)
514
+ setRestartNeeded(false);
515
+ } finally {
516
+ setRestarting(false);
517
+ }
518
+ }, []);
519
+ const markDirty = useCallback2(() => setRestartNeeded(true), []);
520
+ return { restartNeeded, restarting, restart, markDirty };
521
+ }
522
+ // src/hooks/use-query-state.ts
523
+ import { useCallback as useCallback3, useMemo, useRef as useRef2 } from "react";
524
+ "use client";
525
+ function useQueryState(key, defaultValue = "") {
526
+ const searchParams = useSearchParams();
527
+ const router = useRouter();
528
+ const pathname = usePathname();
529
+ const paramsRef = useRef2(searchParams);
530
+ paramsRef.current = searchParams;
531
+ const pathnameRef = useRef2(pathname);
532
+ pathnameRef.current = pathname;
533
+ const value = searchParams.get(key) ?? defaultValue;
534
+ const buildUrl = useCallback3((v) => {
535
+ const params = new URLSearchParams(paramsRef.current.toString());
536
+ if (v === defaultValue) {
537
+ params.delete(key);
538
+ } else {
539
+ params.set(key, v);
540
+ }
541
+ const qs = params.toString();
542
+ return qs ? `${pathnameRef.current}?${qs}` : pathnameRef.current;
543
+ }, [key, defaultValue]);
544
+ const setValue = useCallback3((v) => {
545
+ router.replace(buildUrl(v), { scroll: false });
546
+ }, [router, buildUrl]);
547
+ const pushValue = useCallback3((v) => {
548
+ router.push(buildUrl(v), { scroll: false });
549
+ }, [router, buildUrl]);
550
+ return [value, setValue, pushValue];
551
+ }
552
+ function useQueryArrayState(key) {
553
+ const searchParams = useSearchParams();
554
+ const router = useRouter();
555
+ const pathname = usePathname();
556
+ const paramsRef = useRef2(searchParams);
557
+ paramsRef.current = searchParams;
558
+ const pathnameRef = useRef2(pathname);
559
+ pathnameRef.current = pathname;
560
+ const value = useMemo(() => {
561
+ const raw = searchParams.get(key);
562
+ if (!raw)
563
+ return [];
564
+ return raw.split(",").filter(Boolean);
565
+ }, [searchParams, key]);
566
+ const setValue = useCallback3((v) => {
567
+ const params = new URLSearchParams(paramsRef.current.toString());
568
+ if (v.length === 0) {
569
+ params.delete(key);
570
+ } else {
571
+ params.set(key, v.join(","));
572
+ }
573
+ const qs = params.toString();
574
+ router.replace(qs ? `${pathnameRef.current}?${qs}` : pathnameRef.current, { scroll: false });
575
+ }, [router, key]);
576
+ return [value, setValue];
577
+ }
578
+ // src/hooks/use-schedule.ts
579
+ import { useState as useState3, useEffect as useEffect4, useCallback as useCallback4, useRef as useRef3 } from "react";
580
+ "use client";
581
+ function useScheduleJobs(options = {}) {
582
+ const [jobs, setJobs] = useState3([]);
583
+ const [loading, setLoading] = useState3(true);
584
+ const optionsRef = useRef3(options);
585
+ optionsRef.current = options;
586
+ const fetchJobs = useCallback4(async () => {
587
+ try {
588
+ const res = await fetch("/api/plugins/schedule/");
589
+ if (res.ok) {
590
+ const data = await res.json();
591
+ setJobs(data.jobs || []);
592
+ }
593
+ } catch {} finally {
594
+ setLoading(false);
595
+ }
596
+ }, []);
597
+ useEffect4(() => {
598
+ fetchJobs();
599
+ }, [fetchJobs]);
600
+ useEffect4(() => {
601
+ const es = new EventSource("/api/events");
602
+ const handler = (event) => {
603
+ try {
604
+ const data = JSON.parse(event.data);
605
+ if (data.type === "activity" && data.message?.includes("Schedule") || data.event?.startsWith("schedule.")) {
606
+ fetchJobs();
607
+ }
608
+ } catch {}
609
+ };
610
+ es.addEventListener("message", handler);
611
+ return () => {
612
+ es.removeEventListener("message", handler);
613
+ es.close();
614
+ };
615
+ }, [fetchJobs]);
616
+ const opts = options;
617
+ const filtered = jobs.filter((j) => {
618
+ if (opts.agent && j.agentId !== opts.agent)
619
+ return false;
620
+ return true;
621
+ });
622
+ const pauseJob = useCallback4(async (jobId, pauseUntil) => {
623
+ try {
624
+ const res = await fetch(`/api/plugins/schedule/${jobId}/pause`, {
625
+ method: "POST",
626
+ headers: { "Content-Type": "application/json" },
627
+ body: JSON.stringify({ action: "pause", pauseUntil })
628
+ });
629
+ if (res.ok)
630
+ fetchJobs();
631
+ return res.ok;
632
+ } catch {
633
+ return false;
634
+ }
635
+ }, [fetchJobs]);
636
+ const resumeJob = useCallback4(async (jobId) => {
637
+ try {
638
+ const res = await fetch(`/api/plugins/schedule/${jobId}/pause`, {
639
+ method: "POST",
640
+ headers: { "Content-Type": "application/json" },
641
+ body: JSON.stringify({ action: "resume" })
642
+ });
643
+ if (res.ok)
644
+ fetchJobs();
645
+ return res.ok;
646
+ } catch {
647
+ return false;
648
+ }
649
+ }, [fetchJobs]);
650
+ const deleteJob = useCallback4(async (jobId) => {
651
+ try {
652
+ const res = await fetch(`/api/plugins/schedule/${jobId}`, {
653
+ method: "DELETE",
654
+ headers: { "Content-Type": "application/json" }
655
+ });
656
+ if (res.ok) {
657
+ setJobs((prev) => prev.filter((j) => j.id !== jobId));
658
+ }
659
+ return res.ok;
660
+ } catch {
661
+ return false;
662
+ }
663
+ }, []);
664
+ const runNow = useCallback4(async (jobId) => {
665
+ try {
666
+ const res = await fetch(`/api/plugins/schedule/${jobId}/run`, {
667
+ method: "POST",
668
+ headers: { "Content-Type": "application/json" }
669
+ });
670
+ return res.ok;
671
+ } catch {
672
+ return false;
673
+ }
674
+ }, []);
675
+ const updateJob = useCallback4(async (jobId, data) => {
676
+ try {
677
+ const res = await fetch(`/api/plugins/schedule/${jobId}`, {
678
+ method: "PUT",
679
+ headers: { "Content-Type": "application/json" },
680
+ body: JSON.stringify(data)
681
+ });
682
+ if (res.ok)
683
+ fetchJobs();
684
+ return res.ok;
685
+ } catch {
686
+ return false;
687
+ }
688
+ }, [fetchJobs]);
689
+ const adoptJob = useCallback4(async (jobId, data) => {
690
+ try {
691
+ const res = await fetch(`/api/plugins/schedule/${jobId}/adopt`, {
692
+ method: "POST",
693
+ headers: { "Content-Type": "application/json" },
694
+ body: JSON.stringify(data)
695
+ });
696
+ if (res.ok)
697
+ fetchJobs();
698
+ return res.ok;
699
+ } catch {
700
+ return false;
701
+ }
702
+ }, [fetchJobs]);
703
+ const restoreNative = useCallback4(async (jobId) => {
704
+ try {
705
+ const res = await fetch(`/api/plugins/schedule/${jobId}/restore-native`, {
706
+ method: "POST",
707
+ headers: { "Content-Type": "application/json" }
708
+ });
709
+ if (res.ok)
710
+ fetchJobs();
711
+ return res.ok;
712
+ } catch {
713
+ return false;
714
+ }
715
+ }, [fetchJobs]);
716
+ const skipNext = useCallback4(async (jobId, n = 1) => {
717
+ try {
718
+ const res = await fetch(`/api/plugins/schedule/${jobId}/pause`, {
719
+ method: "POST",
720
+ headers: { "Content-Type": "application/json" },
721
+ body: JSON.stringify({ action: "skip", skipN: n })
722
+ });
723
+ if (res.ok)
724
+ fetchJobs();
725
+ return res.ok;
726
+ } catch {
727
+ return false;
728
+ }
729
+ }, [fetchJobs]);
730
+ const duplicateJob = useCallback4(async (jobId, overrides = {}) => {
731
+ const source = jobs.find((j) => j.id === jobId);
732
+ if (!source)
733
+ return false;
734
+ try {
735
+ const res = await fetch("/api/plugins/schedule/", {
736
+ method: "POST",
737
+ headers: { "Content-Type": "application/json" },
738
+ body: JSON.stringify({
739
+ name: overrides.name ?? `${source.displayName} (copy)`,
740
+ schedule: overrides.schedule ?? source.humanSchedule,
741
+ agentId: overrides.agentId ?? source.agentId,
742
+ taskPrompt: overrides.taskPrompt ?? source.taskPrompt,
743
+ taskTitle: overrides.taskTitle ?? source.taskTitle,
744
+ workflowId: overrides.workflowId ?? source.workflowId,
745
+ owner: overrides.owner ?? source.owner,
746
+ requireTriage: overrides.requireTriage ?? source.requireTriage,
747
+ allowOverlap: overrides.allowOverlap ?? source.allowOverlap,
748
+ maxFailures: overrides.maxFailures ?? source.maxFailures,
749
+ ...overrides
750
+ })
751
+ });
752
+ if (res.ok)
753
+ fetchJobs();
754
+ return res.ok;
755
+ } catch {
756
+ return false;
757
+ }
758
+ }, [jobs, fetchJobs]);
759
+ return {
760
+ jobs: filtered,
761
+ loading,
762
+ refresh: fetchJobs,
763
+ pauseJob,
764
+ resumeJob,
765
+ deleteJob,
766
+ runNow,
767
+ updateJob,
768
+ adoptJob,
769
+ restoreNative,
770
+ skipNext,
771
+ duplicateJob
772
+ };
773
+ }
774
+ function useRunHistory(jobId, limit = 20) {
775
+ const [runs, setRuns] = useState3([]);
776
+ const [loading, setLoading] = useState3(false);
777
+ useEffect4(() => {
778
+ if (!jobId) {
779
+ setRuns([]);
780
+ return;
781
+ }
782
+ setLoading(true);
783
+ fetch(`/api/plugins/schedule/${jobId}/runs?limit=${limit}`).then((res) => res.ok ? res.json() : null).then((data) => {
784
+ if (data)
785
+ setRuns(data.runs || []);
786
+ }).catch(() => {}).finally(() => setLoading(false));
787
+ }, [jobId, limit]);
788
+ return { runs, loading };
789
+ }
790
+ // src/hooks/use-search.ts
791
+ import { useState as useState4, useEffect as useEffect5, useCallback as useCallback5, useRef as useRef4 } from "react";
792
+ "use client";
793
+ function reorderBySearchResults(items, searchResults) {
794
+ if (!searchResults.length)
795
+ return items;
796
+ const scoreMap = new Map;
797
+ for (const r of searchResults) {
798
+ scoreMap.set(r.id, r.score);
799
+ }
800
+ const matched = [];
801
+ const unmatched = [];
802
+ for (const item of items) {
803
+ if (scoreMap.has(item.id)) {
804
+ matched.push(item);
805
+ } else {
806
+ unmatched.push(item);
807
+ }
808
+ }
809
+ matched.sort((a, b) => (scoreMap.get(b.id) ?? 0) - (scoreMap.get(a.id) ?? 0));
810
+ return [...matched, ...unmatched];
811
+ }
812
+ function useSearch(options = {}) {
813
+ const {
814
+ plugin,
815
+ limit = 20,
816
+ facets,
817
+ debounce: debounceMs = 250,
818
+ fallback
819
+ } = options;
820
+ const [results, setResults] = useState4([]);
821
+ const [aggregations, setAggregations] = useState4({});
822
+ const [loading, setLoading] = useState4(false);
823
+ const [error, setError] = useState4(null);
824
+ const [meta, setMeta] = useState4(null);
825
+ const [, setQuery] = useState4("");
826
+ const abortRef = useRef4(null);
827
+ const timerRef = useRef4(null);
828
+ const mountedRef = useRef4(true);
829
+ useEffect5(() => {
830
+ mountedRef.current = true;
831
+ return () => {
832
+ mountedRef.current = false;
833
+ abortRef.current?.abort();
834
+ if (timerRef.current)
835
+ clearTimeout(timerRef.current);
836
+ };
837
+ }, []);
838
+ const executeSearch = useCallback5(async (q) => {
839
+ if (!q.trim()) {
840
+ setResults([]);
841
+ setAggregations({});
842
+ setMeta(null);
843
+ setError(null);
844
+ setLoading(false);
845
+ return;
846
+ }
847
+ abortRef.current?.abort();
848
+ const controller = new AbortController;
849
+ abortRef.current = controller;
850
+ setLoading(true);
851
+ setError(null);
852
+ try {
853
+ const params = new URLSearchParams({ q });
854
+ if (limit)
855
+ params.set("limit", String(limit));
856
+ if (facets?.length)
857
+ params.set("facets", facets.join(","));
858
+ const url = plugin ? `/api/plugins/${plugin}/search?${params}` : `/api/search?${params}`;
859
+ const res = await fetch(url, { signal: controller.signal });
860
+ if (!mountedRef.current)
861
+ return;
862
+ if (!res.ok) {
863
+ throw new Error(`Search failed: ${res.status}`);
864
+ }
865
+ const data = await res.json();
866
+ if (!mountedRef.current)
867
+ return;
868
+ if (data.results.length === 0 && data.meta?.source === "fallback" && fallback) {
869
+ setResults(fallback(q));
870
+ setAggregations({});
871
+ setMeta(data.meta);
872
+ } else {
873
+ setResults(data.results);
874
+ setAggregations(data.aggregations || {});
875
+ setMeta(data.meta || null);
876
+ }
877
+ } catch (err) {
878
+ if (!mountedRef.current)
879
+ return;
880
+ if (err instanceof DOMException && err.name === "AbortError")
881
+ return;
882
+ const msg = err instanceof Error ? err.message : String(err);
883
+ setError(msg);
884
+ if (fallback) {
885
+ setResults(fallback(q));
886
+ setAggregations({});
887
+ } else {
888
+ setResults([]);
889
+ setAggregations({});
890
+ }
891
+ } finally {
892
+ if (mountedRef.current)
893
+ setLoading(false);
894
+ }
895
+ }, [plugin, limit, facets, fallback]);
896
+ const search = useCallback5((q) => {
897
+ setQuery(q);
898
+ if (timerRef.current)
899
+ clearTimeout(timerRef.current);
900
+ if (!q.trim()) {
901
+ setResults([]);
902
+ setAggregations({});
903
+ setMeta(null);
904
+ setError(null);
905
+ setLoading(false);
906
+ return;
907
+ }
908
+ setLoading(true);
909
+ timerRef.current = setTimeout(() => executeSearch(q), debounceMs);
910
+ }, [executeSearch, debounceMs]);
911
+ const clear = useCallback5(() => {
912
+ setQuery("");
913
+ setResults([]);
914
+ setAggregations({});
915
+ setMeta(null);
916
+ setError(null);
917
+ setLoading(false);
918
+ abortRef.current?.abort();
919
+ if (timerRef.current)
920
+ clearTimeout(timerRef.current);
921
+ }, []);
922
+ return { results, aggregations, loading, error, meta, search, clear };
923
+ }
924
+ // src/hooks/use-sidebar.ts
925
+ import { useState as useState5, useEffect as useEffect6 } from "react";
926
+ "use client";
927
+ function useSidebar() {
928
+ const [collapsed, setCollapsed] = useState5(false);
929
+ useEffect6(() => {
930
+ const stored = localStorage.getItem("sidebar-collapsed");
931
+ if (stored === "true")
932
+ setCollapsed(true);
933
+ }, []);
934
+ const toggle = () => setCollapsed((c) => {
935
+ localStorage.setItem("sidebar-collapsed", String(!c));
936
+ return !c;
937
+ });
938
+ return { collapsed, toggle };
939
+ }
940
+ // src/hooks/use-sse.ts
941
+ import { useEffect as useEffect7, useRef as useRef5 } from "react";
942
+
943
+ // src/lib/browser-notify.ts
944
+ var STORAGE_KEY = "bakin-notifications-enabled";
945
+ function isNotificationsSupported() {
946
+ return typeof window !== "undefined" && "Notification" in window && window.isSecureContext;
947
+ }
948
+ function isNotificationsEnabled() {
949
+ if (!isNotificationsSupported())
950
+ return false;
951
+ return localStorage.getItem(STORAGE_KEY) === "true" && Notification.permission === "granted";
952
+ }
953
+ function sendBrowserNotification(title, body) {
954
+ if (!isNotificationsEnabled())
955
+ return;
956
+ if (document.hasFocus())
957
+ return;
958
+ new Notification(title, { body, icon: "/favicon.ico" });
959
+ }
960
+
961
+ // src/hooks/use-sse.ts
962
+ "use client";
963
+ var MAX_RETRIES = 20;
964
+ var BASE_DELAY = 1000;
965
+ var MAX_DELAY = 30000;
966
+ function isDevPluginHotReloadActive() {
967
+ return typeof document !== "undefined" && !!document.querySelector('script[src="/__bakin-dev/client.js"]');
968
+ }
969
+ function useSSE() {
970
+ const updateFile = useContentStore((s) => s.updateFile);
971
+ const setConnected = useContentStore((s) => s.setConnected);
972
+ const setHeartbeats = useContentStore((s) => s.setHeartbeats);
973
+ const initialize = useContentStore((s) => s.initialize);
974
+ const appendAuditEntry = useContentStore((s) => s.appendAuditEntry);
975
+ const appendActivityEvent = useContentStore((s) => s.appendActivityEvent);
976
+ const setSseConnected = useContentStore((s) => s.setSseConnected);
977
+ const bumpTaskboard = useContentStore((s) => s.bumpTaskboard);
978
+ const setReindexProgress = useContentStore((s) => s.setReindexProgress);
979
+ const esRef = useRef5(null);
980
+ const retryRef = useRef5(0);
981
+ const timeoutRef = useRef5(null);
982
+ const hbTimerRef = useRef5(null);
983
+ useEffect7(() => {
984
+ initialize();
985
+ function connect() {
986
+ if (esRef.current) {
987
+ esRef.current.close();
988
+ esRef.current = null;
989
+ }
990
+ const es = new EventSource("/api/events");
991
+ esRef.current = es;
992
+ es.onopen = () => {
993
+ setConnected(true);
994
+ setSseConnected(true);
995
+ retryRef.current = 0;
996
+ };
997
+ es.onmessage = (e) => {
998
+ try {
999
+ const data = JSON.parse(e.data);
1000
+ if (data.type === "taskboard") {
1001
+ bumpTaskboard();
1002
+ return;
1003
+ }
1004
+ if (data.type === "plugin:manifest-changed") {
1005
+ if (!isDevPluginHotReloadActive()) {
1006
+ window.location.reload();
1007
+ }
1008
+ return;
1009
+ }
1010
+ if (data.type === "activity") {
1011
+ appendActivityEvent({
1012
+ id: `${data.ts}-activity-${data.agent}`,
1013
+ ts: data.ts,
1014
+ type: "log",
1015
+ agent: data.agent || "system",
1016
+ message: data.message,
1017
+ taskId: data.taskId
1018
+ });
1019
+ return;
1020
+ }
1021
+ if (data.type === "audit" && data.entry) {
1022
+ const entry = data.entry;
1023
+ const entryData = entry.data || {};
1024
+ appendAuditEntry(entry);
1025
+ appendActivityEvent({
1026
+ id: `${entry.ts}-${entry.event}-${entry.agent}`,
1027
+ ts: entry.ts,
1028
+ type: "audit",
1029
+ agent: entry.agent || "system",
1030
+ message: mapAuditMessage(entry.event, entryData),
1031
+ taskId: entryData.taskId,
1032
+ taskTitle: entryData.title,
1033
+ eventName: entry.event,
1034
+ ...entryData.duplicate ? { duplicate: true } : {}
1035
+ });
1036
+ }
1037
+ if (data.type === "plugin-event" && typeof data.event === "string" && data.event.startsWith("workflow.")) {
1038
+ if (data.event.startsWith("workflow.gate") || data.event === "workflow.complete") {
1039
+ initialize();
1040
+ }
1041
+ if (data.event === "workflow.gate_reached") {
1042
+ sendBrowserNotification("Approval needed", data.label || "A workflow gate needs your review");
1043
+ }
1044
+ appendAuditEntry({
1045
+ ts: data.timestamp || new Date().toISOString(),
1046
+ event: data.event,
1047
+ agent: "workflow",
1048
+ data: { taskId: data.taskId, label: data.label, agent: data.agent, reason: data.reason, workflowId: data.workflowId }
1049
+ });
1050
+ appendActivityEvent({
1051
+ id: `${data.timestamp || new Date().toISOString()}-${data.event}-workflow`,
1052
+ ts: data.timestamp || new Date().toISOString(),
1053
+ type: "audit",
1054
+ agent: "workflow",
1055
+ message: mapAuditMessage(data.event, data),
1056
+ taskId: data.taskId,
1057
+ eventName: data.event
1058
+ });
1059
+ }
1060
+ if (data.type === "alert") {
1061
+ appendActivityEvent({
1062
+ id: `${data.timestamp || new Date().toISOString()}-alert-system`,
1063
+ ts: data.timestamp || new Date().toISOString(),
1064
+ type: "alert",
1065
+ agent: "system",
1066
+ message: data.message || "Watchdog alert"
1067
+ });
1068
+ }
1069
+ if (data.type === "reindex.start") {
1070
+ setReindexProgress(data.table, 0, false);
1071
+ }
1072
+ if (data.type === "reindex.progress") {
1073
+ setReindexProgress(data.table, data.indexed ?? 0, false);
1074
+ }
1075
+ if (data.type === "reindex.complete") {
1076
+ setReindexProgress(data.table, data.indexed ?? 0, true);
1077
+ }
1078
+ if (data.type === "reindex.batch_start") {
1079
+ appendActivityEvent({
1080
+ id: `${Date.now()}-reindex-batch-start`,
1081
+ ts: new Date().toISOString(),
1082
+ type: "log",
1083
+ agent: "system",
1084
+ message: `Starting full re-index (${data.tables} table${data.tables === 1 ? "" : "s"})`
1085
+ });
1086
+ }
1087
+ if (data.type === "reindex.batch_pulse") {
1088
+ const pct = data.tables_total ? Math.floor(data.tables_done / data.tables_total * 100) : 0;
1089
+ appendActivityEvent({
1090
+ id: `${Date.now()}-reindex-batch-pulse`,
1091
+ ts: new Date().toISOString(),
1092
+ type: "log",
1093
+ agent: "system",
1094
+ message: `Re-indexing\u2026 ${data.tables_done}/${data.tables_total} tables (${pct}%), ${data.indexed} documents so far`
1095
+ });
1096
+ }
1097
+ if (data.type === "reindex.batch_complete") {
1098
+ const seconds = Math.max(1, Math.round((data.elapsed_ms ?? 0) / 1000));
1099
+ appendActivityEvent({
1100
+ id: `${Date.now()}-reindex-batch-complete`,
1101
+ ts: new Date().toISOString(),
1102
+ type: "log",
1103
+ agent: "system",
1104
+ message: `Completed full re-index \u2014 ${data.indexed} documents across ${data.tables} table${data.tables === 1 ? "" : "s"} in ${seconds}s`
1105
+ });
1106
+ }
1107
+ if (data.file && data.content !== undefined) {
1108
+ updateFile(data.file, data.content);
1109
+ if (data.file.startsWith("heartbeats/") && data.file.endsWith(".json")) {
1110
+ if (hbTimerRef.current)
1111
+ clearTimeout(hbTimerRef.current);
1112
+ hbTimerRef.current = setTimeout(() => {
1113
+ fetch("/api/agents/health").then((r) => r.ok ? r.json() : null).then((hb) => {
1114
+ if (hb)
1115
+ setHeartbeats(hb);
1116
+ }).catch(() => {});
1117
+ }, 500);
1118
+ }
1119
+ }
1120
+ } catch {}
1121
+ };
1122
+ es.onerror = () => {
1123
+ setConnected(false);
1124
+ setSseConnected(false);
1125
+ es.close();
1126
+ esRef.current = null;
1127
+ if (retryRef.current < MAX_RETRIES) {
1128
+ const delay = Math.min(BASE_DELAY * Math.pow(2, retryRef.current), MAX_DELAY);
1129
+ retryRef.current++;
1130
+ timeoutRef.current = setTimeout(connect, delay);
1131
+ }
1132
+ };
1133
+ }
1134
+ connect();
1135
+ return () => {
1136
+ if (timeoutRef.current)
1137
+ clearTimeout(timeoutRef.current);
1138
+ if (hbTimerRef.current)
1139
+ clearTimeout(hbTimerRef.current);
1140
+ esRef.current?.close();
1141
+ esRef.current = null;
1142
+ };
1143
+ }, [updateFile, setConnected, setHeartbeats, initialize, appendAuditEntry, appendActivityEvent, setSseConnected, bumpTaskboard, setReindexProgress]);
1144
+ }
1145
+ // src/hooks/use-toast.ts
1146
+ var DEFAULT_DURATION = {
1147
+ success: 4000,
1148
+ info: 4000,
1149
+ error: 1e4
1150
+ };
1151
+ var counter = 0;
1152
+ var useToastStore = create((set) => ({
1153
+ toasts: [],
1154
+ add: (toast) => {
1155
+ const id = String(++counter);
1156
+ set((s) => ({ toasts: [...s.toasts, { ...toast, id }] }));
1157
+ setTimeout(() => {
1158
+ set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
1159
+ }, toast.duration ?? DEFAULT_DURATION[toast.type]);
1160
+ },
1161
+ dismiss: (id) => set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }))
1162
+ }));
1163
+ function toast(message, type = "info", duration) {
1164
+ useToastStore.getState().add({ message, type, ...duration ? { duration } : {} });
1165
+ }
1166
+ // src/hooks/use-vertical-resize.ts
1167
+ import { useCallback as useCallback6, useEffect as useEffect8, useRef as useRef6, useState as useState6 } from "react";
1168
+ "use client";
1169
+ var STORAGE_PREFIX = "bakin-vresize:";
1170
+ function clamp(n, min, max) {
1171
+ return Math.min(max, Math.max(min, n));
1172
+ }
1173
+ function readStored(defaultHeight, min, max, storageKey) {
1174
+ if (!storageKey || typeof window === "undefined")
1175
+ return clamp(defaultHeight, min, max);
1176
+ try {
1177
+ const raw = window.localStorage.getItem(STORAGE_PREFIX + storageKey);
1178
+ if (!raw)
1179
+ return clamp(defaultHeight, min, max);
1180
+ const parsed = Number.parseInt(raw, 10);
1181
+ return Number.isFinite(parsed) ? clamp(parsed, min, max) : clamp(defaultHeight, min, max);
1182
+ } catch {
1183
+ return clamp(defaultHeight, min, max);
1184
+ }
1185
+ }
1186
+ function useVerticalResize({ defaultHeight, minHeight, maxHeight, storageKey }) {
1187
+ const [height, setHeightState] = useState6(() => readStored(defaultHeight, minHeight, maxHeight, storageKey));
1188
+ const heightRef = useRef6(height);
1189
+ const dragging = useRef6(false);
1190
+ const startY = useRef6(0);
1191
+ const startHeight = useRef6(0);
1192
+ useEffect8(() => {
1193
+ heightRef.current = height;
1194
+ }, [height]);
1195
+ const persist = useCallback6((h) => {
1196
+ if (!storageKey || typeof window === "undefined")
1197
+ return;
1198
+ try {
1199
+ window.localStorage.setItem(STORAGE_PREFIX + storageKey, String(clamp(h, minHeight, maxHeight)));
1200
+ } catch {}
1201
+ }, [storageKey, minHeight, maxHeight]);
1202
+ const setHeight = useCallback6((h) => {
1203
+ const next = clamp(h, minHeight, maxHeight);
1204
+ heightRef.current = next;
1205
+ setHeightState(next);
1206
+ persist(next);
1207
+ }, [minHeight, maxHeight, persist]);
1208
+ const beginDrag = useCallback6((clientY) => {
1209
+ dragging.current = true;
1210
+ startY.current = clientY;
1211
+ startHeight.current = heightRef.current;
1212
+ }, []);
1213
+ const onMove = useCallback6((clientY) => {
1214
+ if (!dragging.current)
1215
+ return;
1216
+ const delta = startY.current - clientY;
1217
+ const next = clamp(startHeight.current + delta, minHeight, maxHeight);
1218
+ heightRef.current = next;
1219
+ setHeightState(next);
1220
+ }, [minHeight, maxHeight]);
1221
+ const endDrag = useCallback6(() => {
1222
+ if (!dragging.current)
1223
+ return;
1224
+ dragging.current = false;
1225
+ persist(heightRef.current);
1226
+ document.body.style.cursor = "";
1227
+ document.body.style.userSelect = "";
1228
+ }, [persist]);
1229
+ const onMouseDown = useCallback6((e) => {
1230
+ e.preventDefault();
1231
+ beginDrag(e.clientY);
1232
+ const move = (ev) => onMove(ev.clientY);
1233
+ const up = () => {
1234
+ document.removeEventListener("mousemove", move);
1235
+ document.removeEventListener("mouseup", up);
1236
+ endDrag();
1237
+ };
1238
+ document.addEventListener("mousemove", move);
1239
+ document.addEventListener("mouseup", up);
1240
+ document.body.style.cursor = "row-resize";
1241
+ document.body.style.userSelect = "none";
1242
+ }, [beginDrag, onMove, endDrag]);
1243
+ const onTouchStart = useCallback6((e) => {
1244
+ const touch = e.touches[0];
1245
+ if (!touch)
1246
+ return;
1247
+ beginDrag(touch.clientY);
1248
+ const move = (ev) => {
1249
+ const t = ev.touches[0];
1250
+ if (t)
1251
+ onMove(t.clientY);
1252
+ };
1253
+ const up = () => {
1254
+ document.removeEventListener("touchmove", move);
1255
+ document.removeEventListener("touchend", up);
1256
+ document.removeEventListener("touchcancel", up);
1257
+ endDrag();
1258
+ };
1259
+ document.addEventListener("touchmove", move);
1260
+ document.addEventListener("touchend", up);
1261
+ document.addEventListener("touchcancel", up);
1262
+ }, [beginDrag, onMove, endDrag]);
1263
+ return {
1264
+ height,
1265
+ setHeight,
1266
+ handleProps: { onMouseDown, onTouchStart }
1267
+ };
1268
+ }
1269
+ // plugins/team/hooks/use-agent-store.ts
1270
+ "use client";
1271
+ async function parsePackageStatesResponse(res) {
1272
+ if (!res || !res.ok)
1273
+ return {};
1274
+ try {
1275
+ const body = await res.json();
1276
+ if (!body.ok || !Array.isArray(body.agents))
1277
+ return {};
1278
+ const map = {};
1279
+ for (const row of body.agents) {
1280
+ map[row.agentId] = row;
1281
+ }
1282
+ return map;
1283
+ } catch {
1284
+ return {};
1285
+ }
1286
+ }
1287
+ var useAgentStore = create((set, get) => ({
1288
+ agents: [],
1289
+ agentIds: [],
1290
+ agentMap: {},
1291
+ agentsWithStatus: [],
1292
+ displaySettings: {},
1293
+ teams: [],
1294
+ packageStates: {},
1295
+ mainAgentId: null,
1296
+ loaded: false,
1297
+ load: async () => {
1298
+ try {
1299
+ const [rosterRes, pkgRes] = await Promise.all([
1300
+ fetch("/api/plugins/team/"),
1301
+ fetch("/api/agent-packages").catch(() => null)
1302
+ ]);
1303
+ if (!rosterRes.ok) {
1304
+ set({ loaded: true });
1305
+ return;
1306
+ }
1307
+ const data = await rosterRes.json();
1308
+ const agents = data.agents.map(({
1309
+ status: _status,
1310
+ heartbeat: _heartbeat,
1311
+ heartbeatAge: _heartbeatAge,
1312
+ model: _model,
1313
+ ...meta
1314
+ }) => meta);
1315
+ const agentMap = {};
1316
+ for (const a of agents) {
1317
+ agentMap[a.id] = a;
1318
+ }
1319
+ const packageStates = await parsePackageStatesResponse(pkgRes);
1320
+ set({
1321
+ agents,
1322
+ agentIds: agents.map((a) => a.id),
1323
+ agentMap,
1324
+ agentsWithStatus: data.agents,
1325
+ displaySettings: data.displaySettings,
1326
+ teams: data.teams ?? [],
1327
+ packageStates,
1328
+ mainAgentId: data.mainAgentId ?? null,
1329
+ loaded: true
1330
+ });
1331
+ } catch {
1332
+ set({ loaded: true });
1333
+ }
1334
+ },
1335
+ refreshPackageStates: async () => {
1336
+ const res = await fetch("/api/agent-packages").catch(() => null);
1337
+ const packageStates = await parsePackageStatesResponse(res);
1338
+ set({ packageStates });
1339
+ },
1340
+ updateDisplay: async (agentId, patch) => {
1341
+ const current = get().displaySettings;
1342
+ const updated = {
1343
+ ...current,
1344
+ [agentId]: { ...current[agentId], ...patch }
1345
+ };
1346
+ set({ displaySettings: updated });
1347
+ await fetch("/api/plugins/team/settings", {
1348
+ method: "PUT",
1349
+ headers: { "Content-Type": "application/json" },
1350
+ body: JSON.stringify(updated)
1351
+ });
1352
+ }
1353
+ }));
1354
+ function useAgent(agentId) {
1355
+ return useAgentStore((s) => s.agentMap[agentId]);
1356
+ }
1357
+ function useAgentList() {
1358
+ return useAgentStore((s) => s.agents);
1359
+ }
1360
+ function useAgentColor(agentId) {
1361
+ return useAgentStore((s) => s.displaySettings[agentId]?.accentColor ?? "#a1a1aa");
1362
+ }
1363
+ function usePackageState(agentId) {
1364
+ return useAgentStore((s) => s.packageStates?.[agentId]);
1365
+ }
1366
+ function useAgentDisplayName(agentId) {
1367
+ return useAgentStore((s) => s.displaySettings[agentId]?.displayName);
1368
+ }
1369
+ function useAgentIds() {
1370
+ return useAgentStore((s) => s.agentIds);
1371
+ }
1372
+ function useMainAgentId() {
1373
+ return useAgentStore((s) => s.mainAgentId);
1374
+ }
1375
+ function hexToMuted(hex, opacity = 0.2) {
1376
+ const r = parseInt(hex.slice(1, 3), 16);
1377
+ const g = parseInt(hex.slice(3, 5), 16);
1378
+ const b = parseInt(hex.slice(5, 7), 16);
1379
+ return `rgba(${r}, ${g}, ${b}, ${opacity})`;
1380
+ }
1381
+ // plugins/workflows/hooks/use-notification-channels.ts
1382
+ import { useEffect as useEffect9, useState as useState7 } from "react";
1383
+ "use client";
1384
+ var cached = null;
1385
+ var inFlight = null;
1386
+ function fetchChannels() {
1387
+ if (cached)
1388
+ return Promise.resolve(cached);
1389
+ if (inFlight)
1390
+ return inFlight;
1391
+ inFlight = fetch("/api/plugins/workflows/notification-channels").then((r) => r.ok ? r.json() : null).then((data) => {
1392
+ const list = data && Array.isArray(data.channels) ? data.channels : [];
1393
+ cached = list;
1394
+ return list;
1395
+ }).catch(() => {
1396
+ cached = [];
1397
+ return [];
1398
+ }).finally(() => {
1399
+ inFlight = null;
1400
+ });
1401
+ return inFlight;
1402
+ }
1403
+ function useNotificationChannels() {
1404
+ const [channels, setChannels] = useState7(() => cached ?? []);
1405
+ useEffect9(() => {
1406
+ if (cached)
1407
+ return;
1408
+ let cancelled = false;
1409
+ fetchChannels().then((list) => {
1410
+ if (!cancelled)
1411
+ setChannels(list);
1412
+ });
1413
+ return () => {
1414
+ cancelled = true;
1415
+ };
1416
+ }, []);
1417
+ return channels;
1418
+ }
1419
+ function getChannelLabel(id, channels) {
1420
+ return channels.find((c) => c.id === id)?.label ?? id;
1421
+ }
1422
+ function getChannelInitials(id, channels) {
1423
+ const match = channels.find((c) => c.id === id);
1424
+ if (match?.initials)
1425
+ return match.initials;
1426
+ return id.slice(0, 2).toUpperCase();
1427
+ }
1428
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/matchContext.js
1429
+ import * as React$1 from "react";
1430
+ "use client";
1431
+ var matchContext = React$1.createContext(undefined);
1432
+ var dummyMatchContext = React$1.createContext(undefined);
1433
+
1434
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/routerContext.js
1435
+ import * as React$12 from "react";
1436
+ "use client";
1437
+ var routerContext = React$12.createContext(null);
1438
+
1439
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/useRouter.js
1440
+ import * as React$13 from "react";
1441
+ "use client";
1442
+ function useRouter2(opts) {
1443
+ const value = React$13.useContext(routerContext);
1444
+ if (true) {
1445
+ if ((opts?.warn ?? true) && !value)
1446
+ console.warn("Warning: useRouter must be used inside a <RouterProvider> component!");
1447
+ }
1448
+ return value;
1449
+ }
1450
+
1451
+ // node_modules/.bun/@tanstack+router-core@1.168.15/node_modules/@tanstack/router-core/dist/esm/isServer/development.js
1452
+ var isServer = undefined;
1453
+
1454
+ // node_modules/.bun/@tanstack+router-core@1.168.15/node_modules/@tanstack/router-core/dist/esm/utils.js
1455
+ var hasOwn = Object.prototype.hasOwnProperty;
1456
+ var isEnumerable = Object.prototype.propertyIsEnumerable;
1457
+ function replaceEqualDeep(prev, _next, _makeObj = () => ({}), _depth = 0) {
1458
+ if (isServer)
1459
+ return _next;
1460
+ if (prev === _next)
1461
+ return prev;
1462
+ if (_depth > 500)
1463
+ return _next;
1464
+ const next = _next;
1465
+ const array = isPlainArray(prev) && isPlainArray(next);
1466
+ if (!array && !(isPlainObject(prev) && isPlainObject(next)))
1467
+ return next;
1468
+ const prevItems = array ? prev : getEnumerableOwnKeys(prev);
1469
+ if (!prevItems)
1470
+ return next;
1471
+ const nextItems = array ? next : getEnumerableOwnKeys(next);
1472
+ if (!nextItems)
1473
+ return next;
1474
+ const prevSize = prevItems.length;
1475
+ const nextSize = nextItems.length;
1476
+ const copy = array ? new Array(nextSize) : _makeObj();
1477
+ let equalItems = 0;
1478
+ for (let i = 0;i < nextSize; i++) {
1479
+ const key = array ? i : nextItems[i];
1480
+ const p = prev[key];
1481
+ const n = next[key];
1482
+ if (p === n) {
1483
+ copy[key] = p;
1484
+ if (array ? i < prevSize : hasOwn.call(prev, key))
1485
+ equalItems++;
1486
+ continue;
1487
+ }
1488
+ if (p === null || n === null || typeof p !== "object" || typeof n !== "object") {
1489
+ copy[key] = n;
1490
+ continue;
1491
+ }
1492
+ const v = replaceEqualDeep(p, n, _makeObj, _depth + 1);
1493
+ copy[key] = v;
1494
+ if (v === p)
1495
+ equalItems++;
1496
+ }
1497
+ return prevSize === nextSize && equalItems === prevSize ? prev : copy;
1498
+ }
1499
+ function getEnumerableOwnKeys(o) {
1500
+ const names = Object.getOwnPropertyNames(o);
1501
+ for (const name of names)
1502
+ if (!isEnumerable.call(o, name))
1503
+ return false;
1504
+ const symbols = Object.getOwnPropertySymbols(o);
1505
+ if (symbols.length === 0)
1506
+ return names;
1507
+ const keys = names;
1508
+ for (const symbol of symbols) {
1509
+ if (!isEnumerable.call(o, symbol))
1510
+ return false;
1511
+ keys.push(symbol);
1512
+ }
1513
+ return keys;
1514
+ }
1515
+ function isPlainObject(o) {
1516
+ if (!hasObjectPrototype(o))
1517
+ return false;
1518
+ const ctor = o.constructor;
1519
+ if (typeof ctor === "undefined")
1520
+ return true;
1521
+ const prot = ctor.prototype;
1522
+ if (!hasObjectPrototype(prot))
1523
+ return false;
1524
+ if (!prot.hasOwnProperty("isPrototypeOf"))
1525
+ return false;
1526
+ return true;
1527
+ }
1528
+ function hasObjectPrototype(o) {
1529
+ return Object.prototype.toString.call(o) === "[object Object]";
1530
+ }
1531
+ function isPlainArray(value) {
1532
+ return Array.isArray(value) && value.length === Object.keys(value).length;
1533
+ }
1534
+
1535
+ // node_modules/.bun/@tanstack+router-core@1.168.15/node_modules/@tanstack/router-core/dist/esm/invariant.js
1536
+ function invariant() {
1537
+ throw new Error("Invariant failed");
1538
+ }
1539
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/useMatch.js
1540
+ import * as React$14 from "react";
1541
+ // node_modules/.bun/@tanstack+react-store@0.9.3+bf16f8eded5e12ee/node_modules/@tanstack/react-store/dist/esm/useStore.js
1542
+ var import_with_selector = __toESM(require_with_selector(), 1);
1543
+ import { useCallback as useCallback7 } from "react";
1544
+ function defaultCompare(a, b) {
1545
+ return a === b;
1546
+ }
1547
+ function useStore2(atom, selector, compare = defaultCompare) {
1548
+ const subscribe = useCallback7((handleStoreChange) => {
1549
+ if (!atom) {
1550
+ return () => {};
1551
+ }
1552
+ const { unsubscribe } = atom.subscribe(handleStoreChange);
1553
+ return unsubscribe;
1554
+ }, [atom]);
1555
+ const boundGetSnapshot = useCallback7(() => atom?.get(), [atom]);
1556
+ const selectedSnapshot = import_with_selector.useSyncExternalStoreWithSelector(subscribe, boundGetSnapshot, boundGetSnapshot, selector, compare);
1557
+ return selectedSnapshot;
1558
+ }
1559
+
1560
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/useMatch.js
1561
+ "use client";
1562
+ var dummyStore = {
1563
+ get: () => {
1564
+ return;
1565
+ },
1566
+ subscribe: () => ({ unsubscribe: () => {} })
1567
+ };
1568
+ function useMatch(opts) {
1569
+ const router = useRouter2();
1570
+ const nearestMatchId = React$14.useContext(opts.from ? dummyMatchContext : matchContext);
1571
+ const key = opts.from ?? nearestMatchId;
1572
+ const matchStore = key ? opts.from ? router.stores.getRouteMatchStore(key) : router.stores.matchStores.get(key) : undefined;
1573
+ if (isServer ?? router.isServer) {
1574
+ const match = matchStore?.get();
1575
+ if ((opts.shouldThrow ?? true) && !match) {
1576
+ if (true)
1577
+ throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
1578
+ invariant();
1579
+ }
1580
+ if (match === undefined)
1581
+ return;
1582
+ return opts.select ? opts.select(match) : match;
1583
+ }
1584
+ const previousResult = React$14.useRef(undefined);
1585
+ return useStore2(matchStore ?? dummyStore, (match) => {
1586
+ if ((opts.shouldThrow ?? true) && !match) {
1587
+ if (true)
1588
+ throw new Error(`Invariant failed: Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`);
1589
+ invariant();
1590
+ }
1591
+ if (match === undefined)
1592
+ return;
1593
+ const selected = opts.select ? opts.select(match) : match;
1594
+ if (opts.structuralSharing ?? router.options.defaultStructuralSharing) {
1595
+ const shared = replaceEqualDeep(previousResult.current, selected);
1596
+ previousResult.current = shared;
1597
+ return shared;
1598
+ }
1599
+ return selected;
1600
+ });
1601
+ }
1602
+
1603
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/useParams.js
1604
+ function useParams(opts) {
1605
+ return useMatch({
1606
+ from: opts.from,
1607
+ shouldThrow: opts.shouldThrow,
1608
+ structuralSharing: opts.structuralSharing,
1609
+ strict: opts.strict,
1610
+ select: (match) => {
1611
+ const params = opts.strict === false ? match.params : match._strictParams;
1612
+ return opts.select ? opts.select(params) : params;
1613
+ }
1614
+ });
1615
+ }
1616
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/useNavigate.js
1617
+ import * as React$15 from "react";
1618
+ "use client";
1619
+ function useNavigate(_defaultOpts) {
1620
+ const router = useRouter2();
1621
+ return React$15.useCallback((options) => {
1622
+ return router.navigate({
1623
+ ...options,
1624
+ from: options.from ?? _defaultOpts?.from
1625
+ });
1626
+ }, [_defaultOpts?.from, router]);
1627
+ }
1628
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/useLocation.js
1629
+ import { useRef as useRef9 } from "react";
1630
+ function useLocation(opts) {
1631
+ const router = useRouter2();
1632
+ if (isServer ?? router.isServer) {
1633
+ const location = router.stores.location.get();
1634
+ return opts?.select ? opts.select(location) : location;
1635
+ }
1636
+ const previousResult = useRef9(undefined);
1637
+ return useStore2(router.stores.location, (location) => {
1638
+ const selected = opts?.select ? opts.select(location) : location;
1639
+ if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {
1640
+ const shared = replaceEqualDeep(previousResult.current, selected);
1641
+ previousResult.current = shared;
1642
+ return shared;
1643
+ }
1644
+ return selected;
1645
+ });
1646
+ }
1647
+
1648
+ // node_modules/.bun/@tanstack+react-router@1.168.23+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/index.dev.js
1649
+ "use client";
1650
+
1651
+ // packages/sdk/src/hooks/router.ts
1652
+ import { useMemo as useMemo2 } from "react";
1653
+ function useRouter() {
1654
+ const navigate = useNavigate();
1655
+ return useMemo2(() => ({
1656
+ push: (url) => {
1657
+ navigate({ to: url });
1658
+ },
1659
+ replace: (url) => {
1660
+ navigate({ to: url, replace: true });
1661
+ },
1662
+ back: () => {
1663
+ if (typeof window !== "undefined")
1664
+ window.history.back();
1665
+ },
1666
+ forward: () => {
1667
+ if (typeof window !== "undefined")
1668
+ window.history.forward();
1669
+ },
1670
+ refresh: () => {
1671
+ if (typeof window !== "undefined")
1672
+ window.location.reload();
1673
+ },
1674
+ prefetch: () => {}
1675
+ }), [navigate]);
1676
+ }
1677
+ function usePathname() {
1678
+ const location = useLocation();
1679
+ return location.pathname;
1680
+ }
1681
+ function useSearchParams() {
1682
+ const location = useLocation();
1683
+ return useMemo2(() => {
1684
+ const search = location.searchStr;
1685
+ if (typeof search === "string") {
1686
+ return new URLSearchParams(search.startsWith("?") ? search.slice(1) : search);
1687
+ }
1688
+ const parsed = location.search;
1689
+ if (parsed && typeof parsed === "object") {
1690
+ const params = new URLSearchParams;
1691
+ for (const [k, v] of Object.entries(parsed)) {
1692
+ if (v === undefined || v === null)
1693
+ continue;
1694
+ params.set(k, String(v));
1695
+ }
1696
+ return params;
1697
+ }
1698
+ return new URLSearchParams;
1699
+ }, [location]);
1700
+ }
1701
+ function useParams2() {
1702
+ return useParams({ strict: false });
1703
+ }
1704
+ export {
1705
+ useVerticalResize,
1706
+ useTrash,
1707
+ useToastStore,
1708
+ useSidebar,
1709
+ useSearchParams,
1710
+ useSearch,
1711
+ useScheduleJobs,
1712
+ useSSE,
1713
+ useRuntimeStatus,
1714
+ useRunHistory,
1715
+ useRouter,
1716
+ useQueryState,
1717
+ useQueryArrayState,
1718
+ usePathname,
1719
+ useParams2 as useParams,
1720
+ usePackageState,
1721
+ useNotificationChannels,
1722
+ useMainAgentId,
1723
+ useFormGuard,
1724
+ useDebug,
1725
+ useContentStore,
1726
+ useAssets,
1727
+ useAgentStore,
1728
+ useAgentList,
1729
+ useAgentIds,
1730
+ useAgentDisplayName,
1731
+ useAgentColor,
1732
+ useAgent,
1733
+ toast,
1734
+ reorderBySearchResults,
1735
+ hexToMuted,
1736
+ getChannelLabel,
1737
+ getChannelInitials
1738
+ };