bazilion 0.55.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +192 -37
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +1164 -412
- package/dist/daemon.js.map +1 -1
- package/dist/web/client/assets/AddProviderDialog-DZ9mXFdq.js +1 -0
- package/dist/web/client/assets/AgentTemplateParts-BfG3a-ri.js +1 -0
- package/dist/web/client/assets/{Button-bTJUy9Qf.js → Button-CoKQRO-s.js} +1 -1
- package/dist/web/client/assets/ConfigPage-Ch-DSJUO.js +1 -0
- package/dist/web/client/assets/ConfirmDialog-B_jXAPmh.js +1 -0
- package/dist/web/client/assets/ConnectionsView-D1Liebtf.js +1 -0
- package/dist/web/client/assets/ManagePage-kd7iWYEL.js +1 -0
- package/dist/web/client/assets/{SectionTabs-D7kPQGoh.js → SectionTabs-Dc0bNn-J.js} +1 -1
- package/dist/web/client/assets/{Segmented-oPkAHPO1.js → Segmented-iylzLwE6.js} +1 -1
- package/dist/web/client/assets/SkillsParts-C5T7sYDA.js +1 -0
- package/dist/web/client/assets/SpawnTeamModal-DatFF4f_.js +1 -0
- package/dist/web/client/assets/TeamForm-l-N_PYeE.js +1 -0
- package/dist/web/client/assets/TeamThread-BWmIQiAh.js +1 -0
- package/dist/web/client/assets/UnsavedChangesGuard-vQBdMl8h.js +1 -0
- package/dist/web/client/assets/_id-C6SADaiD.js +1 -0
- package/dist/web/client/assets/_id-CC9r0qsr.js +1 -0
- package/dist/web/client/assets/access-BbQFbTPh.js +1 -0
- package/dist/web/client/assets/{agent-actions-CUee6aJq.js → agent-actions-B-9KIwn6.js} +1 -1
- package/dist/web/client/assets/agents-BXwzmHu8.js +1 -0
- package/dist/web/client/assets/agents-BtETzVIY.js +1 -0
- package/dist/web/client/assets/arrow-right-BqqfPqVi.js +1 -0
- package/dist/web/client/assets/attention-BMrZJ9ui.js +1 -0
- package/dist/web/client/assets/{bot-BCone8es.js → bot-BHky7KAX.js} +1 -1
- package/dist/web/client/assets/chart-column-DTsDbzL0.js +1 -0
- package/dist/web/client/assets/chevron-right-D1shxvdo.js +1 -0
- package/dist/web/client/assets/config-B2ZDYo52.js +1 -0
- package/dist/web/client/assets/{createLucideIcon-jxSFpY0Q.js → createLucideIcon-CZHSSDYA.js} +1 -1
- package/dist/web/client/assets/{download-Dy88XavQ.js → download-Dr0PgyMr.js} +1 -1
- package/dist/web/client/assets/es2015-D1pnOGPG.js +41 -0
- package/dist/web/client/assets/{file-text-DPsZ8-h9.js → file-text-D6OTHixJ.js} +1 -1
- package/dist/web/client/assets/{images-QBh_rL8b.js → images-BULrW-FC.js} +1 -1
- package/dist/web/client/assets/index-B-N6NIX4.js +14 -0
- package/dist/web/client/assets/{key-round-C-I8fAG0.js → key-round-DmSZN0Kq.js} +1 -1
- package/dist/web/client/assets/{list-checks-C9Q-bjEi.js → list-checks-DdTdAQXS.js} +1 -1
- package/dist/web/client/assets/login-DM3q-V4R.js +1 -0
- package/dist/web/client/assets/{manage-BaIU5zKy.js → manage-R57MUzsY.js} +1 -1
- package/dist/web/client/assets/mcp-CSHrVH1t.js +1 -0
- package/dist/web/client/assets/{message-square-Bwf9cHOx.js → message-square-B_pULba_.js} +1 -1
- package/dist/web/client/assets/{network-B3FA93gC.js → network-BqmVqC4_.js} +1 -1
- package/dist/web/client/assets/parts-68zf8Fgw.js +1 -0
- package/dist/web/client/assets/plus-CEKaHPBw.js +1 -0
- package/dist/web/client/assets/preload-helper-CZOd_z6l.js +1 -0
- package/dist/web/client/assets/routes-DOoeKVwr.js +85 -0
- package/dist/web/client/assets/skills-CPZftp9O.js +1 -0
- package/dist/web/client/assets/{square-terminal-DaNLwvEs.js → square-terminal-CYfGBHPC.js} +1 -1
- package/dist/web/client/assets/style-Bm9QsFpy.js +7 -0
- package/dist/web/client/assets/styles-B-kTTvCo.css +2 -0
- package/dist/web/client/assets/{system-CrTSr5_t.js → system-Dd2P9eqE.js} +1 -1
- package/dist/web/client/assets/teams-7FEpSZg1.js +1 -0
- package/dist/web/client/assets/teams-ClirFbDV.js +1 -0
- package/dist/web/client/assets/telegram-BJnT5THs.js +1 -0
- package/dist/web/client/assets/tools-DqNXLMpc.js +1 -0
- package/dist/web/client/assets/usage-BC_TStVj.js +1 -0
- package/dist/web/client/assets/use-resource-Bn0Sx7r6.js +1 -0
- package/dist/web/client/assets/{users-round-BElBVSnw.js → users-round-cxQ5HF-C.js} +1 -1
- package/dist/web/client/assets/welcome-g8wtn_or.js +1 -0
- package/dist/web/client/assets/{wrench-DotqSqSm.js → wrench-BLEJjETg.js} +1 -1
- package/dist/web/server/assets/{AddProviderDialog-BbpuvC2a.js → AddProviderDialog-DtkjBMv4.js} +5 -2
- package/dist/web/server/assets/AgentAvatar-8gTAy_tP.js +37 -0
- package/dist/web/server/assets/{AgentTemplateParts-Ce7snK3m.js → AgentTemplateParts-CxWyovvM.js} +6 -2
- package/dist/web/server/assets/Button-Dsnw22OF.js +17 -0
- package/dist/web/server/assets/{ConfigPage-qP9ejjuw.js → ConfigPage-usZi48Zr.js} +2 -2
- package/dist/web/server/assets/{ConfirmDialog-Z-uYbE9B.js → ConfirmDialog-DAcSBHkT.js} +3 -1
- package/dist/web/server/assets/{ConnectionsView-CLIV7V5D.js → ConnectionsView-Dy6uYSRI.js} +9 -7
- package/dist/web/server/assets/Dialog-DTeF-nOZ.js +85 -0
- package/dist/web/server/assets/{ManagePage-BR9FwVZM.js → ManagePage-Dy1EdovO.js} +2 -2
- package/dist/web/server/assets/{SectionTabs-CWQ5orUW.js → SectionTabs-BVrMn76H.js} +2 -1
- package/dist/web/server/assets/{SkillsParts-DWpdydCJ.js → SkillsParts-Cw05b3al.js} +6 -2
- package/dist/web/server/assets/SpawnDialog-BAE8W91z.js +125 -0
- package/dist/web/server/assets/{SpawnTeamModal-C-YMvoaB.js → SpawnTeamModal-CgBY0HuN.js} +6 -2
- package/dist/web/server/assets/{TeamForm-CL45gBdt.js → TeamForm-JyO5xJXX.js} +6 -2
- package/dist/web/server/assets/{TeamThread-CVVH6kKj.js → TeamThread-5o48EbXL.js} +52 -4
- package/dist/web/server/assets/{UnsavedChangesGuard-CXK75QQp.js → UnsavedChangesGuard-CJQGu45L.js} +1 -1
- package/dist/web/server/assets/{_id-8zsImuGa.js → _id-BE_RSvuN.js} +14 -9
- package/dist/web/server/assets/{_id-d2OwovYV.js → _id-BNvm89oJ.js} +2 -2
- package/dist/web/server/assets/{_id-De3Bm0SG.js → _id-BW6sVrvw.js} +1 -1
- package/dist/web/server/assets/{_id-2I4CSMQj.js → _id-BfjTS4JO.js} +15 -9
- package/dist/web/server/assets/{_id-BKzOw78O.js → _id-BpumuCYL.js} +1 -1
- package/dist/web/server/assets/{_id-BpfoPuTv.js → _id-C54t_nX6.js} +2 -2
- package/dist/web/server/assets/_tanstack-start-manifest_v-BPwQX_5b.js +275 -0
- package/dist/web/server/assets/{access-CwZ27Wsl.js → access-6FWih7nC.js} +7 -4
- package/dist/web/server/assets/{access-WWspT0v4.js → access-BhAMfi7U.js} +1 -1
- package/dist/web/server/assets/{access-CyUoElTP.js → access-DEyq3uP_.js} +2 -2
- package/dist/web/server/assets/activity-Czfq-5_F.js +471 -0
- package/dist/web/server/assets/{agent-actions-C07Cp5Ue.js → agent-actions-ChH7Mne4.js} +1 -1
- package/dist/web/server/assets/{agents-CRtMfKqX.js → agents-3hBjrd8B.js} +1 -1
- package/dist/web/server/assets/{agents-vuXrAv1j.js → agents-BXuglv4G.js} +12 -6
- package/dist/web/server/assets/{agents-DTub-rJk.js → agents-DhenbitX.js} +2 -2
- package/dist/web/server/assets/{agents-CwzhpDPm.js → agents-KJcDMj0Y.js} +9 -6
- package/dist/web/server/assets/{agents-DCWEoaxY.js → agents-ncyhVx-T.js} +2 -2
- package/dist/web/server/assets/{agents-DQowl6Ly.js → agents-rTDlRZa5.js} +1 -1
- package/dist/web/server/assets/{attention-BqCnJ1hg.js → attention-CDdOCOio.js} +2 -2
- package/dist/web/server/assets/{attention-DwGaur_w.js → attention-DM__BzWY.js} +8 -6
- package/dist/web/server/assets/{attention-Dki8rmGZ.js → attention-X0U6ZmiA.js} +1 -1
- package/dist/web/server/assets/{auth-dJnrFW6y.js → auth-BexhV8Yq.js} +1 -1
- package/dist/web/server/assets/{config-B9dJiji_.js → config-Cld8Q8N7.js} +2 -2
- package/dist/web/server/assets/{config-X7qWbbpH.js → config-Cx5ri2DL2.js} +1 -1
- package/dist/web/server/assets/{config-D3MR2VjE.js → config-DpgYAXQ3.js} +9 -6
- package/dist/web/server/assets/createSsrRpc-6LHNEsSK.js +16 -0
- package/dist/web/server/assets/{daemon-client-B_ZRIIrT.js → daemon-client-RxAllljf.js} +1 -1
- package/dist/web/server/assets/form-BEjeiSy3.js +416 -0
- package/dist/web/server/assets/live-DbJeq6KP.js +263 -0
- package/dist/web/server/assets/{login-CRd1yTH5.js → login-BJdJ219n.js} +1 -1
- package/dist/web/server/assets/{login-ZN6KV8n-.js → login-C4lL4AxI.js} +2 -2
- package/dist/web/server/assets/{manage-Ce6cI4eW.js → manage-C6ucNYZW.js} +2 -1
- package/dist/web/server/assets/{mcp-BQ15a9dG.js → mcp-BXnWQOwM.js} +7 -4
- package/dist/web/server/assets/{mcp-C97uAZe1.js → mcp-C8VLspco.js} +1 -1
- package/dist/web/server/assets/{mcp-CYQuYWGX.js → mcp-DwCzj7eO.js} +2 -2
- package/dist/web/server/assets/open-groups-BMGYUTtY.js +12 -0
- package/dist/web/server/assets/{page-title-CVY-c2Pd.js → page-title-PTpFHXWo.js} +1 -1
- package/dist/web/server/assets/parts-k9M-atPa.js +436 -0
- package/dist/web/server/assets/{router-CPdWGKQ5.js → router-BttfLktO.js} +185 -77
- package/dist/web/server/assets/{routes-BPloBDc8.js → routes-A7UcreVX.js} +3 -3
- package/dist/web/server/assets/{routes-Dw1K3TQw.js → routes-B9jw-MJ8.js} +1175 -321
- package/dist/web/server/assets/{routes-xDPesCQu.js → routes-BX2FV8rS.js} +3 -3
- package/dist/web/server/assets/{skills-D0xrNc2_.js → skills-BVAH93cd.js} +8 -6
- package/dist/web/server/assets/{skills-DWzlT_hC.js → skills-Cd5Cfdaz.js} +1 -1
- package/dist/web/server/assets/{skills-6VSpEORe.js → skills-y3GsyKce.js} +2 -2
- package/dist/web/server/assets/src-vrZVrV9u.js +103 -0
- package/dist/web/server/assets/{start-DhW7sy23.js → start-Dl8gQ-95.js} +1 -1
- package/dist/web/server/assets/{style-aMybyKzc.js → style-BQ3H9I7Y.js} +1 -1
- package/dist/web/server/assets/{system-B5sPgdQW.js → system-BJPKqM6b.js} +2 -2
- package/dist/web/server/assets/{system-CXmiWyDG.js → system-C7mejQSc.js} +3 -3
- package/dist/web/server/assets/{system-D3th6n2E.js → system-LsLcuVzY.js} +1 -1
- package/dist/web/server/assets/{teams-yF3I_Zjq.js → teams-B6gbflsZ.js} +10 -6
- package/dist/web/server/assets/{teams-iXiCnN2i.js → teams-C7kXMNgc.js} +10 -6
- package/dist/web/server/assets/{teams-BopOP4x7.js → teams-CPXoTggb.js} +1 -1
- package/dist/web/server/assets/{teams-70u1XQTr.js → teams-CeLLd2Mf.js} +1 -1
- package/dist/web/server/assets/{teams-ClRBVSYU.js → teams-CiX8LUQo.js} +2 -2
- package/dist/web/server/assets/{teams-Dq4RCxis.js → teams-D-XdIkCr.js} +2 -2
- package/dist/web/server/assets/{telegram-CGol0CKX2.js → telegram-D7TW3LNZ.js} +1 -1
- package/dist/web/server/assets/{telegram-DwEgyR1x.js → telegram-D8_V7_sW.js} +286 -272
- package/dist/web/server/assets/{telegram-D9U9c1MN.js → telegram-DA2dwLID.js} +2 -2
- package/dist/web/server/assets/{tools-VPIKjr3y.js → tools-CckcG9Jl.js} +5 -3
- package/dist/web/server/assets/{tools-DflVIdDd.js → tools-CluiJywK.js} +2 -2
- package/dist/web/server/assets/{tools-C-wwWjLI.js → tools-D1BBVkRh.js} +1 -1
- package/dist/web/server/assets/usage-CrYyvPgf.js +46 -0
- package/dist/web/server/assets/usage-PNNb3pPj.js +465 -0
- package/dist/web/server/assets/{use-resource-CbHGYti0.js → use-resource-BUA9qGGY.js} +1 -1
- package/dist/web/server/assets/{welcome-CxXMI4HI.js → welcome-CUTYf8UG.js} +1 -1
- package/dist/web/server/assets/{welcome-966nOyyK.js → welcome-CYhh3iUU.js} +8 -6
- package/dist/web/server/assets/{welcome-7DrYZVs6.js → welcome-CwzLt6Rp.js} +2 -2
- package/dist/web/server/assets/workspace-0XPILV1W.js +82 -0
- package/dist/web/server/server.js +20 -20
- package/dist/worker.js +27 -6
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/web/client/assets/AddProviderDialog-DfFOaCjC.js +0 -1
- package/dist/web/client/assets/AgentTemplateParts-IMJmAQjN.js +0 -1
- package/dist/web/client/assets/ConfigPage-CzLHZa5o.js +0 -1
- package/dist/web/client/assets/ConfirmDialog-Cu_evkgc.js +0 -1
- package/dist/web/client/assets/ConnectionsView-D7Fmutl2.js +0 -1
- package/dist/web/client/assets/ManagePage-BfvlCrmz.js +0 -1
- package/dist/web/client/assets/SkillsParts-BuTxcCam.js +0 -1
- package/dist/web/client/assets/SpawnTeamModal-B1UnOvtp.js +0 -1
- package/dist/web/client/assets/TeamForm-DbzxtRjj.js +0 -1
- package/dist/web/client/assets/TeamThread-jpsWq6vI.js +0 -1
- package/dist/web/client/assets/UnsavedChangesGuard-BfyU9v9i.js +0 -1
- package/dist/web/client/assets/_id-BCNBLF-2.js +0 -1
- package/dist/web/client/assets/_id-D8_H79U2.js +0 -1
- package/dist/web/client/assets/access-CDWe1Kwy.js +0 -1
- package/dist/web/client/assets/agents-sE686DTf.js +0 -1
- package/dist/web/client/assets/agents-yrur1NDa.js +0 -1
- package/dist/web/client/assets/arrow-right-U66krZnr.js +0 -1
- package/dist/web/client/assets/attention-DYEHDfmx.js +0 -1
- package/dist/web/client/assets/chevron-right-CuqJFXTe.js +0 -1
- package/dist/web/client/assets/config-BHv886pr.js +0 -1
- package/dist/web/client/assets/index-GOthyyE-.js +0 -14
- package/dist/web/client/assets/login-Dhe15Uuc.js +0 -1
- package/dist/web/client/assets/mcp-A_Eo7x3q.js +0 -1
- package/dist/web/client/assets/parts-CpIfn_BH.js +0 -41
- package/dist/web/client/assets/plus-CQPjc8uR.js +0 -1
- package/dist/web/client/assets/routes-CTg_yjbY.js +0 -85
- package/dist/web/client/assets/skills-CLjtYtkA.js +0 -1
- package/dist/web/client/assets/style-mjEbxhf5.js +0 -7
- package/dist/web/client/assets/styles-DzcEC3Rd.css +0 -2
- package/dist/web/client/assets/teams-Bhje5n2h.js +0 -1
- package/dist/web/client/assets/teams-Cbgw0Qhv.js +0 -1
- package/dist/web/client/assets/telegram-HtUczmaA.js +0 -1
- package/dist/web/client/assets/tools-BpjFvmoX.js +0 -1
- package/dist/web/client/assets/use-resource-BnvgCpBi.js +0 -1
- package/dist/web/client/assets/welcome-D47LKWYO.js +0 -1
- package/dist/web/server/assets/Rail-b6EbjBB-.js +0 -605
- package/dist/web/server/assets/SpawnDialog-3wNx0W1R.js +0 -1851
- package/dist/web/server/assets/_tanstack-start-manifest_v-kkY_s_uR.js +0 -256
- package/dist/web/server/assets/createSsrRpc-qesavJv-.js +0 -72
- package/dist/web/server/assets/public-origin-BpDkdS5Q.js +0 -34
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { i as getServerFnById, r as TSS_SERVER_FUNCTION } from "../server.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@tanstack+start-server-core@1.169.17/node_modules/@tanstack/start-server-core/dist/esm/createSsrRpc.js
|
|
3
|
+
var createSsrRpc = (functionId) => {
|
|
4
|
+
const url = "/_serverFn/" + functionId;
|
|
5
|
+
const serverFnMeta = { id: functionId };
|
|
6
|
+
const fn = async (...args) => {
|
|
7
|
+
return (await getServerFnById(functionId, { origin: "server" }))(...args);
|
|
8
|
+
};
|
|
9
|
+
return Object.assign(fn, {
|
|
10
|
+
url,
|
|
11
|
+
serverFnMeta,
|
|
12
|
+
[TSS_SERVER_FUNCTION]: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createSsrRpc as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as getCookie } from "../server.js";
|
|
2
|
-
import {
|
|
2
|
+
import { o as publicOriginConfig } from "./src-vrZVrV9u.js";
|
|
3
3
|
//#region ../../packages/client/src/index.ts
|
|
4
4
|
var ApiClientError = class extends Error {
|
|
5
5
|
status;
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { t as Button } from "./Button-Dsnw22OF.js";
|
|
2
|
+
import { p as cn } from "./ModelMenu-D-hTgYOO.js";
|
|
3
|
+
import { b as Switch } from "./parts-k9M-atPa.js";
|
|
4
|
+
import { useId, useState } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { Check, ChevronDown } from "lucide-react";
|
|
7
|
+
import { Select } from "radix-ui";
|
|
8
|
+
//#region src/components/ui/form.tsx
|
|
9
|
+
var LABEL = "m-0 text-sm font-semibold text-foreground";
|
|
10
|
+
var HINT = "mt-1 block text-xs text-muted-foreground";
|
|
11
|
+
/** What is wrong with a value, said under its field. */
|
|
12
|
+
function Problem({ children }) {
|
|
13
|
+
return /* @__PURE__ */ jsx("span", {
|
|
14
|
+
role: "alert",
|
|
15
|
+
className: "mt-1 block text-xs font-semibold text-warning",
|
|
16
|
+
children
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** A line of text to type: an address, an id, a name. Or a time of day. */
|
|
20
|
+
function TextField({ label, value, onChange, type = "text", placeholder, hint, problem, notes, invalid, disabled, required, mono = false, inputMode, className }) {
|
|
21
|
+
const id = useId();
|
|
22
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
23
|
+
/* @__PURE__ */ jsx("label", {
|
|
24
|
+
htmlFor: id,
|
|
25
|
+
className: LABEL,
|
|
26
|
+
children: label
|
|
27
|
+
}),
|
|
28
|
+
/* @__PURE__ */ jsx("input", {
|
|
29
|
+
id,
|
|
30
|
+
type,
|
|
31
|
+
value,
|
|
32
|
+
disabled,
|
|
33
|
+
required,
|
|
34
|
+
inputMode,
|
|
35
|
+
autoComplete: "off",
|
|
36
|
+
spellCheck: false,
|
|
37
|
+
placeholder: placeholder ?? "",
|
|
38
|
+
"aria-invalid": problem || invalid ? true : void 0,
|
|
39
|
+
onChange: (event) => onChange(event.target.value),
|
|
40
|
+
className: cn("mt-1.5 max-w-xl", mono && "font-mono", className)
|
|
41
|
+
}),
|
|
42
|
+
hint && /* @__PURE__ */ jsx("span", {
|
|
43
|
+
className: HINT,
|
|
44
|
+
children: hint
|
|
45
|
+
}),
|
|
46
|
+
notes,
|
|
47
|
+
problem && /* @__PURE__ */ jsx(Problem, { children: problem })
|
|
48
|
+
] });
|
|
49
|
+
}
|
|
50
|
+
/** Several lines of text: a message, a note. */
|
|
51
|
+
function TextAreaField({ label, value, onChange, placeholder, hint, problem, rows = 4, mono = false, disabled, required }) {
|
|
52
|
+
const id = useId();
|
|
53
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
54
|
+
/* @__PURE__ */ jsx("label", {
|
|
55
|
+
htmlFor: id,
|
|
56
|
+
className: LABEL,
|
|
57
|
+
children: label
|
|
58
|
+
}),
|
|
59
|
+
/* @__PURE__ */ jsx("textarea", {
|
|
60
|
+
id,
|
|
61
|
+
value,
|
|
62
|
+
rows,
|
|
63
|
+
disabled,
|
|
64
|
+
required,
|
|
65
|
+
spellCheck: !mono,
|
|
66
|
+
placeholder: placeholder ?? "",
|
|
67
|
+
"aria-invalid": problem ? true : void 0,
|
|
68
|
+
onChange: (event) => onChange(event.target.value),
|
|
69
|
+
className: cn("mt-1.5 w-full", mono && "font-mono text-[0.9em]")
|
|
70
|
+
}),
|
|
71
|
+
hint && /* @__PURE__ */ jsx("span", {
|
|
72
|
+
className: HINT,
|
|
73
|
+
children: hint
|
|
74
|
+
}),
|
|
75
|
+
problem && /* @__PURE__ */ jsx(Problem, { children: problem })
|
|
76
|
+
] });
|
|
77
|
+
}
|
|
78
|
+
/** A choice between a few options that each need a sentence: radio cards, two abreast. */
|
|
79
|
+
function ChoiceCards({ legend, name, value, options, onChange, disabled = false, notes, columns = 2 }) {
|
|
80
|
+
const id = useId();
|
|
81
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
82
|
+
className: "m-0 min-w-0 border-0 p-0",
|
|
83
|
+
disabled,
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsx("legend", {
|
|
86
|
+
className: "mb-2 p-0 text-sm font-semibold text-foreground",
|
|
87
|
+
children: legend
|
|
88
|
+
}),
|
|
89
|
+
/* @__PURE__ */ jsx("div", {
|
|
90
|
+
className: cn("grid gap-2", columns === 3 ? "md:grid-cols-3" : "md:grid-cols-2"),
|
|
91
|
+
children: options.map((option, index) => {
|
|
92
|
+
const selected = option.value === value;
|
|
93
|
+
const titleId = `${id}-${index}`;
|
|
94
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
95
|
+
className: cn("m-0 flex items-start gap-3 rounded-xl border px-3.5 py-3 transition-colors", disabled ? "cursor-default opacity-70" : "cursor-pointer", selected ? "border-primary/50 bg-accent/40" : "border-border bg-card hover:bg-muted/40"),
|
|
96
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
97
|
+
type: "radio",
|
|
98
|
+
name,
|
|
99
|
+
value: option.value,
|
|
100
|
+
checked: selected,
|
|
101
|
+
onChange: () => onChange(option.value),
|
|
102
|
+
"aria-labelledby": titleId,
|
|
103
|
+
"aria-describedby": `${titleId}-about`,
|
|
104
|
+
className: "mt-[3px] size-[18px] shrink-0 accent-[var(--color-sapphire)]"
|
|
105
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
106
|
+
className: "min-w-0",
|
|
107
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
108
|
+
id: titleId,
|
|
109
|
+
className: "block text-sm font-semibold text-foreground",
|
|
110
|
+
children: option.label
|
|
111
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
112
|
+
id: `${titleId}-about`,
|
|
113
|
+
className: "block",
|
|
114
|
+
children: [option.hint && /* @__PURE__ */ jsx("span", {
|
|
115
|
+
className: "block break-words text-sm text-muted-foreground",
|
|
116
|
+
children: option.hint
|
|
117
|
+
}), selected && option.note && /* @__PURE__ */ jsx("span", {
|
|
118
|
+
className: cn("mt-1 block break-words text-sm font-medium", option.note.tone === "ok" ? "text-success" : "text-warning"),
|
|
119
|
+
children: option.note.text
|
|
120
|
+
})]
|
|
121
|
+
})]
|
|
122
|
+
})]
|
|
123
|
+
}, option.value);
|
|
124
|
+
})
|
|
125
|
+
}),
|
|
126
|
+
notes
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
var EMPTY = ":none";
|
|
131
|
+
var FIELD_TRIGGER = "flex min-h-[2.65rem] w-full items-center justify-between gap-2 rounded-[var(--radius-md)] border border-frost bg-[color-mix(in_srgb,var(--color-snow)_82%,var(--color-ivory))] px-[0.8rem] py-[0.5rem] text-left text-[0.95em] text-chocolate transition-all focus-visible:border-sapphire focus-visible:bg-snow focus-visible:shadow-[0_0_0_3px_var(--color-sapphire-glow)] disabled:cursor-not-allowed disabled:opacity-60 data-[state=open]:border-sapphire";
|
|
132
|
+
var FILTER_TRIGGER = "inline-flex min-h-9 w-auto max-w-full items-center gap-2 rounded-[12px] border border-border bg-card py-1 pl-2.5 pr-2 text-left text-xs font-semibold text-foreground transition-all hover:border-sapphire-light focus-visible:border-sapphire focus-visible:shadow-[0_0_0_3px_var(--color-sapphire-glow)] disabled:opacity-60 data-[state=open]:border-sapphire";
|
|
133
|
+
var ITEM = "relative flex cursor-pointer select-none items-baseline gap-x-3 rounded-lg py-2 pl-8 pr-3 text-sm outline-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground";
|
|
134
|
+
/**
|
|
135
|
+
* The app's one dropdown, drawn like the model menu: the choice in a field, the options in a list
|
|
136
|
+
* with a tick by the chosen one. The keyboard works as in any list (arrows, letters, Enter).
|
|
137
|
+
*/
|
|
138
|
+
function SelectMenu({ value, options, onChange, disabled, id, labelledBy, ariaLabel, placeholder, compact = false, className }) {
|
|
139
|
+
const valueId = useId();
|
|
140
|
+
const chosen = options.find((option) => option.value === value);
|
|
141
|
+
return /* @__PURE__ */ jsxs(Select.Root, {
|
|
142
|
+
value: value === "" ? chosen ? EMPTY : "" : value,
|
|
143
|
+
onValueChange: (next) => onChange(next === EMPTY ? "" : next),
|
|
144
|
+
disabled,
|
|
145
|
+
children: [/* @__PURE__ */ jsxs(Select.Trigger, {
|
|
146
|
+
id,
|
|
147
|
+
"aria-label": ariaLabel,
|
|
148
|
+
"aria-labelledby": labelledBy ? `${labelledBy} ${valueId}` : void 0,
|
|
149
|
+
className: cn(compact ? FILTER_TRIGGER : FIELD_TRIGGER, className),
|
|
150
|
+
style: { outline: "none" },
|
|
151
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
152
|
+
id: valueId,
|
|
153
|
+
className: "min-w-0 flex-1 truncate",
|
|
154
|
+
children: chosen ? chosen.label : /* @__PURE__ */ jsx("span", {
|
|
155
|
+
className: "text-mocha-light",
|
|
156
|
+
children: placeholder ?? "Choose…"
|
|
157
|
+
})
|
|
158
|
+
}), /* @__PURE__ */ jsx(Select.Icon, {
|
|
159
|
+
asChild: true,
|
|
160
|
+
children: /* @__PURE__ */ jsx(ChevronDown, {
|
|
161
|
+
className: cn("shrink-0 text-mocha-light", compact ? "size-3.5" : "size-4"),
|
|
162
|
+
"aria-hidden": "true"
|
|
163
|
+
})
|
|
164
|
+
})]
|
|
165
|
+
}), /* @__PURE__ */ jsx(Select.Portal, { children: /* @__PURE__ */ jsx(Select.Content, {
|
|
166
|
+
position: "popper",
|
|
167
|
+
sideOffset: 6,
|
|
168
|
+
className: "z-50 max-h-[min(24rem,var(--radix-select-content-available-height))] min-w-[max(var(--radix-select-trigger-width),12rem)] max-w-[calc(100vw-1.5rem)] overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-baziu-lg",
|
|
169
|
+
children: /* @__PURE__ */ jsx(Select.Viewport, {
|
|
170
|
+
className: "p-1.5",
|
|
171
|
+
children: options.map((option) => /* @__PURE__ */ jsxs(Select.Item, {
|
|
172
|
+
value: option.value === "" ? EMPTY : option.value,
|
|
173
|
+
className: ITEM,
|
|
174
|
+
style: { outline: "none" },
|
|
175
|
+
children: [
|
|
176
|
+
/* @__PURE__ */ jsx(Select.ItemIndicator, {
|
|
177
|
+
className: "absolute left-2.5 top-1/2 -translate-y-1/2",
|
|
178
|
+
children: /* @__PURE__ */ jsx(Check, {
|
|
179
|
+
className: "size-4 text-primary",
|
|
180
|
+
"aria-hidden": "true"
|
|
181
|
+
})
|
|
182
|
+
}),
|
|
183
|
+
/* @__PURE__ */ jsx(Select.ItemText, {
|
|
184
|
+
asChild: true,
|
|
185
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
186
|
+
className: "min-w-0 flex-1 break-words font-semibold",
|
|
187
|
+
children: option.label
|
|
188
|
+
})
|
|
189
|
+
}),
|
|
190
|
+
option.hint && /* @__PURE__ */ jsx("span", {
|
|
191
|
+
className: "shrink-0 text-xs text-muted-foreground",
|
|
192
|
+
children: option.hint
|
|
193
|
+
})
|
|
194
|
+
]
|
|
195
|
+
}, option.value))
|
|
196
|
+
})
|
|
197
|
+
}) })]
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/** One of a few fixed choices, where a line of radio cards would be too much. */
|
|
201
|
+
function SelectField({ label, value, options, onChange, hint, disabled, placeholder, className }) {
|
|
202
|
+
const id = useId();
|
|
203
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
204
|
+
/* @__PURE__ */ jsx("label", {
|
|
205
|
+
id: `${id}-label`,
|
|
206
|
+
htmlFor: id,
|
|
207
|
+
className: LABEL,
|
|
208
|
+
children: label
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ jsx(SelectMenu, {
|
|
211
|
+
id,
|
|
212
|
+
labelledBy: `${id}-label`,
|
|
213
|
+
value,
|
|
214
|
+
options,
|
|
215
|
+
onChange,
|
|
216
|
+
disabled,
|
|
217
|
+
placeholder,
|
|
218
|
+
className: cn("mt-1.5 max-w-xl", className)
|
|
219
|
+
}),
|
|
220
|
+
hint && /* @__PURE__ */ jsx("span", {
|
|
221
|
+
className: HINT,
|
|
222
|
+
children: hint
|
|
223
|
+
})
|
|
224
|
+
] });
|
|
225
|
+
}
|
|
226
|
+
/** A filter in a card's toolbar: a small dropdown named by its label, which is read, not shown. */
|
|
227
|
+
function FilterSelect({ label, value, options, onChange }) {
|
|
228
|
+
return /* @__PURE__ */ jsx(SelectMenu, {
|
|
229
|
+
compact: true,
|
|
230
|
+
ariaLabel: label,
|
|
231
|
+
value,
|
|
232
|
+
options,
|
|
233
|
+
onChange
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* A key or token. A saved one is never shown or put back into a field: the row says that it is
|
|
238
|
+
* saved, and it is replaced or removed from there. Both wait for the form's Save.
|
|
239
|
+
*/
|
|
240
|
+
function SecretField({ label, saved, preview, value, onChange, removed = false, onRemove, open = false, placeholder, hint, notes, disabled }) {
|
|
241
|
+
const id = useId();
|
|
242
|
+
const [replacing, setReplacing] = useState(false);
|
|
243
|
+
const [kept, setKept] = useState(false);
|
|
244
|
+
const [moved, setMoved] = useState(null);
|
|
245
|
+
const typing = !saved || replacing || open;
|
|
246
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
247
|
+
/* @__PURE__ */ jsx("label", {
|
|
248
|
+
id: `${id}-label`,
|
|
249
|
+
htmlFor: typing ? id : void 0,
|
|
250
|
+
className: LABEL,
|
|
251
|
+
children: label
|
|
252
|
+
}),
|
|
253
|
+
typing ? /* @__PURE__ */ jsxs("div", {
|
|
254
|
+
className: "mt-1.5 flex max-w-xl flex-wrap items-center gap-2",
|
|
255
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
256
|
+
id,
|
|
257
|
+
type: "password",
|
|
258
|
+
value,
|
|
259
|
+
disabled,
|
|
260
|
+
autoComplete: "off",
|
|
261
|
+
spellCheck: false,
|
|
262
|
+
placeholder: placeholder ?? "",
|
|
263
|
+
autoFocus: replacing,
|
|
264
|
+
onChange: (event) => onChange(event.target.value),
|
|
265
|
+
className: "min-w-0 flex-1 basis-56 font-mono"
|
|
266
|
+
}), saved && !open && /* @__PURE__ */ jsx(Button, {
|
|
267
|
+
variant: "ghost",
|
|
268
|
+
disabled,
|
|
269
|
+
onClick: () => {
|
|
270
|
+
onChange("");
|
|
271
|
+
setReplacing(false);
|
|
272
|
+
setKept(true);
|
|
273
|
+
},
|
|
274
|
+
children: "Keep the saved one"
|
|
275
|
+
})]
|
|
276
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
277
|
+
role: "group",
|
|
278
|
+
"aria-labelledby": `${id}-label`,
|
|
279
|
+
className: "mt-1.5 flex min-h-[2.65rem] max-w-xl flex-wrap items-center gap-x-3 gap-y-2 rounded-xl border border-border bg-muted/40 px-3.5 py-1.5 text-sm",
|
|
280
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
281
|
+
className: "min-w-0 flex-1 basis-40 text-foreground",
|
|
282
|
+
children: removed ? "Will be removed when you save." : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
283
|
+
"Saved: ",
|
|
284
|
+
/* @__PURE__ */ jsx("span", {
|
|
285
|
+
className: "font-mono",
|
|
286
|
+
children: preview || "•••"
|
|
287
|
+
}),
|
|
288
|
+
", stored encrypted"
|
|
289
|
+
] })
|
|
290
|
+
}), removed ? /* @__PURE__ */ jsx(Button, {
|
|
291
|
+
variant: "ghost",
|
|
292
|
+
disabled,
|
|
293
|
+
autoFocus: moved === "keep",
|
|
294
|
+
onClick: () => {
|
|
295
|
+
setMoved("remove");
|
|
296
|
+
onRemove?.(false);
|
|
297
|
+
},
|
|
298
|
+
children: "Keep it"
|
|
299
|
+
}) : /* @__PURE__ */ jsxs("span", {
|
|
300
|
+
className: "flex gap-2",
|
|
301
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
302
|
+
variant: "ghost",
|
|
303
|
+
disabled,
|
|
304
|
+
autoFocus: kept,
|
|
305
|
+
onClick: () => setReplacing(true),
|
|
306
|
+
children: "Replace"
|
|
307
|
+
}), onRemove && /* @__PURE__ */ jsx(Button, {
|
|
308
|
+
variant: "ghost",
|
|
309
|
+
disabled,
|
|
310
|
+
autoFocus: moved === "remove",
|
|
311
|
+
onClick: () => {
|
|
312
|
+
setMoved("keep");
|
|
313
|
+
onRemove(true);
|
|
314
|
+
},
|
|
315
|
+
children: "Remove"
|
|
316
|
+
})]
|
|
317
|
+
})]
|
|
318
|
+
}),
|
|
319
|
+
hint && /* @__PURE__ */ jsx("span", {
|
|
320
|
+
className: HINT,
|
|
321
|
+
children: hint
|
|
322
|
+
}),
|
|
323
|
+
notes
|
|
324
|
+
] });
|
|
325
|
+
}
|
|
326
|
+
/** A yes/no setting: what it is on the left, the switch on the right. */
|
|
327
|
+
function SwitchRow({ label, description, notes, checked, disabled, onChange }) {
|
|
328
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
329
|
+
className: "flex items-start justify-between gap-4",
|
|
330
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
331
|
+
className: "min-w-0",
|
|
332
|
+
children: [
|
|
333
|
+
/* @__PURE__ */ jsx("div", {
|
|
334
|
+
className: "text-sm font-semibold text-foreground",
|
|
335
|
+
children: label
|
|
336
|
+
}),
|
|
337
|
+
description && /* @__PURE__ */ jsx("div", {
|
|
338
|
+
className: "text-sm text-muted-foreground",
|
|
339
|
+
children: description
|
|
340
|
+
}),
|
|
341
|
+
notes
|
|
342
|
+
]
|
|
343
|
+
}), /* @__PURE__ */ jsx(Switch, {
|
|
344
|
+
label,
|
|
345
|
+
checked,
|
|
346
|
+
disabled,
|
|
347
|
+
onChange
|
|
348
|
+
})]
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/** One of several things to tick. */
|
|
352
|
+
function CheckboxRow({ label, checked, disabled, onChange }) {
|
|
353
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
354
|
+
className: "m-0 flex items-center gap-2.5 text-sm text-foreground",
|
|
355
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
356
|
+
type: "checkbox",
|
|
357
|
+
checked,
|
|
358
|
+
disabled,
|
|
359
|
+
onChange: (event) => onChange(event.target.checked),
|
|
360
|
+
className: "m-0 size-[18px] shrink-0"
|
|
361
|
+
}), label]
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Where a form stands, in the words every Setup form uses: what was refused, what is not saved
|
|
366
|
+
* yet, what was just saved, or else what to know about saving it.
|
|
367
|
+
*/
|
|
368
|
+
function saveStatus({ refused = false, error, dirty, saved, savedText = "Saved.", footnote = "" }) {
|
|
369
|
+
if (refused) return {
|
|
370
|
+
text: "Nothing was saved: see above.",
|
|
371
|
+
tone: "warning"
|
|
372
|
+
};
|
|
373
|
+
if (error) return {
|
|
374
|
+
text: `Nothing was saved: ${error}`,
|
|
375
|
+
tone: "warning"
|
|
376
|
+
};
|
|
377
|
+
if (dirty) return {
|
|
378
|
+
text: "Not saved yet.",
|
|
379
|
+
tone: "warning"
|
|
380
|
+
};
|
|
381
|
+
if (saved) return {
|
|
382
|
+
text: savedText,
|
|
383
|
+
tone: "success"
|
|
384
|
+
};
|
|
385
|
+
return {
|
|
386
|
+
text: footnote,
|
|
387
|
+
tone: "neutral"
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
var STATUS = {
|
|
391
|
+
success: "text-success",
|
|
392
|
+
warning: "text-warning",
|
|
393
|
+
neutral: "text-muted-foreground"
|
|
394
|
+
};
|
|
395
|
+
/** A form's last line: Save, and where things stand. */
|
|
396
|
+
function SaveBar({ busy, disabled, status, label = "Save", busyLabel = "Saving…", extra }) {
|
|
397
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
398
|
+
className: "flex flex-wrap items-center gap-x-4 gap-y-2",
|
|
399
|
+
children: [
|
|
400
|
+
/* @__PURE__ */ jsx(Button, {
|
|
401
|
+
variant: "primary",
|
|
402
|
+
type: "submit",
|
|
403
|
+
disabled: disabled || busy,
|
|
404
|
+
children: busy ? busyLabel : label
|
|
405
|
+
}),
|
|
406
|
+
extra,
|
|
407
|
+
/* @__PURE__ */ jsx("p", {
|
|
408
|
+
role: "status",
|
|
409
|
+
className: cn("m-0 min-w-0 flex-1 basis-56 text-sm font-medium", STATUS[status.tone]),
|
|
410
|
+
children: status.text
|
|
411
|
+
})
|
|
412
|
+
]
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
export { SaveBar as a, SelectMenu as c, TextField as d, saveStatus as f, Problem as i, SwitchRow as l, ChoiceCards as n, SecretField as o, FilterSelect as r, SelectField as s, CheckboxRow as t, TextAreaField as u };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { r as readCookie, t as CSRF_COOKIES } from "./cookies-HnTYjKRp.js";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/lib/api.ts
|
|
5
|
+
var ApiError = class extends Error {
|
|
6
|
+
status;
|
|
7
|
+
/** The daemon's machine-readable `code`, when it sent one. */
|
|
8
|
+
code;
|
|
9
|
+
/** The parsed JSON error body, when there was one. */
|
|
10
|
+
body;
|
|
11
|
+
constructor(message, status, code, body) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.body = body;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function csrfHeader() {
|
|
19
|
+
for (const name of CSRF_COOKIES) {
|
|
20
|
+
const value = readCookie(document.cookie, name);
|
|
21
|
+
if (value) return { "x-bazilion-csrf": value };
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
async function failure(response) {
|
|
26
|
+
const text = await response.text().catch(() => "");
|
|
27
|
+
let body = {};
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(text);
|
|
30
|
+
if (parsed && typeof parsed === "object") body = parsed;
|
|
31
|
+
} catch {}
|
|
32
|
+
const message = typeof body.error === "string" ? body.error : text.slice(0, 300) || `HTTP ${response.status}`;
|
|
33
|
+
const code = typeof body.code === "string" ? body.code : void 0;
|
|
34
|
+
return new ApiError(message, response.status, code, body);
|
|
35
|
+
}
|
|
36
|
+
/** The raw response (streams, downloads, text); throws ApiError unless it is ok. */
|
|
37
|
+
async function apiFetch(path, init = {}) {
|
|
38
|
+
const method = init.method ?? (init.body === void 0 ? "GET" : "POST");
|
|
39
|
+
const headers = method === "GET" ? {} : csrfHeader();
|
|
40
|
+
let body;
|
|
41
|
+
if (init.body instanceof FormData) body = init.body;
|
|
42
|
+
else if (init.body !== void 0) {
|
|
43
|
+
headers["content-type"] = "application/json";
|
|
44
|
+
body = JSON.stringify(init.body);
|
|
45
|
+
}
|
|
46
|
+
const response = await fetch(path, {
|
|
47
|
+
method,
|
|
48
|
+
headers,
|
|
49
|
+
body,
|
|
50
|
+
signal: init.signal
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) throw await failure(response);
|
|
53
|
+
return response;
|
|
54
|
+
}
|
|
55
|
+
/** The daemon's JSON answer (undefined for an empty body); throws ApiError with its message. */
|
|
56
|
+
async function api(path, init = {}) {
|
|
57
|
+
const text = await (await apiFetch(path, init)).text();
|
|
58
|
+
return text ? JSON.parse(text) : void 0;
|
|
59
|
+
}
|
|
60
|
+
function errorMessage(error) {
|
|
61
|
+
return error instanceof Error ? error.message : String(error);
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/lib/live.tsx
|
|
65
|
+
var CHANNEL = "bazilion-live";
|
|
66
|
+
var LOCK = "bazilion-live";
|
|
67
|
+
var EVENT_TYPES = ["activity", "attention"];
|
|
68
|
+
/** After a failed stream: wait, then try again, longer each time up to the last. */
|
|
69
|
+
var RETRY_MS = [
|
|
70
|
+
1e3,
|
|
71
|
+
3e3,
|
|
72
|
+
1e4,
|
|
73
|
+
3e4
|
|
74
|
+
];
|
|
75
|
+
var LiveContext = createContext({
|
|
76
|
+
connected: false,
|
|
77
|
+
subscribe: () => () => {},
|
|
78
|
+
isLeader: () => false,
|
|
79
|
+
anyTabFocused: () => true
|
|
80
|
+
});
|
|
81
|
+
function useLive() {
|
|
82
|
+
return useContext(LiveContext);
|
|
83
|
+
}
|
|
84
|
+
/** Parse one SSE message's data; null for anything that is not a live event. */
|
|
85
|
+
function parseLiveEvent(data) {
|
|
86
|
+
try {
|
|
87
|
+
const event = JSON.parse(data);
|
|
88
|
+
return event && EVENT_TYPES.includes(event.type) ? event : null;
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function LiveProvider({ enabled, children }) {
|
|
94
|
+
const [connected, setConnected] = useState(false);
|
|
95
|
+
const handlers = useRef(/* @__PURE__ */ new Map());
|
|
96
|
+
const latest = useRef(/* @__PURE__ */ new Map());
|
|
97
|
+
const leading = useRef(false);
|
|
98
|
+
const focusedTabs = useRef(/* @__PURE__ */ new Set());
|
|
99
|
+
const deliver = useCallback((event) => {
|
|
100
|
+
latest.current.set(event.type, event);
|
|
101
|
+
for (const handler of handlers.current.get(event.type) ?? []) try {
|
|
102
|
+
handler(event);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.warn("live feed reader failed:", error);
|
|
105
|
+
}
|
|
106
|
+
}, []);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (!enabled) return;
|
|
109
|
+
let stopped = false;
|
|
110
|
+
let source = null;
|
|
111
|
+
let retry;
|
|
112
|
+
let failures = 0;
|
|
113
|
+
const tab = Math.random().toString(36).slice(2);
|
|
114
|
+
const channel = typeof BroadcastChannel === "undefined" ? null : new BroadcastChannel(CHANNEL);
|
|
115
|
+
const shared = Boolean(channel && typeof navigator !== "undefined" && navigator.locks);
|
|
116
|
+
const post = (message) => channel?.postMessage(message);
|
|
117
|
+
const share = (message) => {
|
|
118
|
+
if (shared) post(message);
|
|
119
|
+
};
|
|
120
|
+
let releaseLock = () => {};
|
|
121
|
+
const status = (value) => {
|
|
122
|
+
setConnected(value);
|
|
123
|
+
share({
|
|
124
|
+
kind: "status",
|
|
125
|
+
connected: value
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const open = () => {
|
|
129
|
+
if (stopped || !shared && document.visibilityState === "hidden") return;
|
|
130
|
+
source = new EventSource("/api/events");
|
|
131
|
+
for (const type of EVENT_TYPES) source.addEventListener(type, (message) => {
|
|
132
|
+
const event = parseLiveEvent(message.data);
|
|
133
|
+
if (!event) return;
|
|
134
|
+
failures = 0;
|
|
135
|
+
deliver(event);
|
|
136
|
+
share({
|
|
137
|
+
kind: "event",
|
|
138
|
+
event
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
source.onopen = () => status(true);
|
|
142
|
+
source.onerror = () => {
|
|
143
|
+
status(false);
|
|
144
|
+
if (source?.readyState === EventSource.CLOSED) {
|
|
145
|
+
source = null;
|
|
146
|
+
const wait = RETRY_MS[Math.min(failures, RETRY_MS.length - 1)] ?? 3e4;
|
|
147
|
+
failures++;
|
|
148
|
+
retry = window.setTimeout(open, wait);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const lead = () => {
|
|
153
|
+
leading.current = true;
|
|
154
|
+
open();
|
|
155
|
+
};
|
|
156
|
+
const reportFocus = () => {
|
|
157
|
+
const focused = document.visibilityState === "visible" && document.hasFocus();
|
|
158
|
+
if (focused) focusedTabs.current.add(tab);
|
|
159
|
+
else focusedTabs.current.delete(tab);
|
|
160
|
+
post({
|
|
161
|
+
kind: "focus",
|
|
162
|
+
tab,
|
|
163
|
+
focused
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
if (channel) channel.onmessage = ({ data }) => {
|
|
167
|
+
if (data.kind === "event") {
|
|
168
|
+
if (shared) deliver(data.event);
|
|
169
|
+
} else if (data.kind === "status") {
|
|
170
|
+
if (shared) setConnected(data.connected);
|
|
171
|
+
} else if (data.kind === "focus") if (data.focused) focusedTabs.current.add(data.tab);
|
|
172
|
+
else focusedTabs.current.delete(data.tab);
|
|
173
|
+
else if (data.kind === "hello") {
|
|
174
|
+
if (leading.current) {
|
|
175
|
+
for (const event of latest.current.values()) post({
|
|
176
|
+
kind: "event",
|
|
177
|
+
event
|
|
178
|
+
});
|
|
179
|
+
post({
|
|
180
|
+
kind: "status",
|
|
181
|
+
connected: source?.readyState === EventSource.OPEN
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
reportFocus();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const close = () => {
|
|
188
|
+
window.clearTimeout(retry);
|
|
189
|
+
source?.close();
|
|
190
|
+
source = null;
|
|
191
|
+
setConnected(false);
|
|
192
|
+
};
|
|
193
|
+
const onVisibility = () => {
|
|
194
|
+
if (document.visibilityState === "hidden") close();
|
|
195
|
+
else if (!source) open();
|
|
196
|
+
};
|
|
197
|
+
if (shared) {
|
|
198
|
+
navigator.locks.request(LOCK, () => {
|
|
199
|
+
if (stopped) return;
|
|
200
|
+
lead();
|
|
201
|
+
return new Promise((resolve) => {
|
|
202
|
+
releaseLock = resolve;
|
|
203
|
+
});
|
|
204
|
+
}).catch(() => {});
|
|
205
|
+
post({ kind: "hello" });
|
|
206
|
+
} else {
|
|
207
|
+
leading.current = true;
|
|
208
|
+
if (document.visibilityState !== "hidden") open();
|
|
209
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
210
|
+
}
|
|
211
|
+
reportFocus();
|
|
212
|
+
window.addEventListener("focus", reportFocus);
|
|
213
|
+
window.addEventListener("blur", reportFocus);
|
|
214
|
+
document.addEventListener("visibilitychange", reportFocus);
|
|
215
|
+
const leave = () => post({
|
|
216
|
+
kind: "focus",
|
|
217
|
+
tab,
|
|
218
|
+
focused: false
|
|
219
|
+
});
|
|
220
|
+
window.addEventListener("pagehide", leave);
|
|
221
|
+
return () => {
|
|
222
|
+
stopped = true;
|
|
223
|
+
leave();
|
|
224
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
225
|
+
window.clearTimeout(retry);
|
|
226
|
+
source?.close();
|
|
227
|
+
leading.current = false;
|
|
228
|
+
releaseLock();
|
|
229
|
+
window.removeEventListener("focus", reportFocus);
|
|
230
|
+
window.removeEventListener("blur", reportFocus);
|
|
231
|
+
document.removeEventListener("visibilitychange", reportFocus);
|
|
232
|
+
window.removeEventListener("pagehide", leave);
|
|
233
|
+
channel?.close();
|
|
234
|
+
setConnected(false);
|
|
235
|
+
};
|
|
236
|
+
}, [enabled, deliver]);
|
|
237
|
+
const subscribe = useCallback((type, handler) => {
|
|
238
|
+
const generic = handler;
|
|
239
|
+
let set = handlers.current.get(type);
|
|
240
|
+
if (!set) {
|
|
241
|
+
set = /* @__PURE__ */ new Set();
|
|
242
|
+
handlers.current.set(type, set);
|
|
243
|
+
}
|
|
244
|
+
set.add(generic);
|
|
245
|
+
const last = latest.current.get(type);
|
|
246
|
+
if (last) generic(last);
|
|
247
|
+
return () => {
|
|
248
|
+
set.delete(generic);
|
|
249
|
+
};
|
|
250
|
+
}, []);
|
|
251
|
+
const value = useMemo(() => ({
|
|
252
|
+
connected,
|
|
253
|
+
subscribe,
|
|
254
|
+
isLeader: () => leading.current,
|
|
255
|
+
anyTabFocused: () => focusedTabs.current.size > 0
|
|
256
|
+
}), [connected, subscribe]);
|
|
257
|
+
return /* @__PURE__ */ jsx(LiveContext.Provider, {
|
|
258
|
+
value,
|
|
259
|
+
children
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
//#endregion
|
|
263
|
+
export { apiFetch as a, api as i, useLive as n, errorMessage as o, ApiError as r, LiveProvider as t };
|