@hansenexus/hud 0.3.0 → 0.5.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/README.md +782 -6
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/access-C7zlaqj6.js +100 -0
- package/dist/access-D_ewAEJG.d.ts +61 -0
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/env-CApnbI0r.d.ts +19 -0
- package/dist/env-CaiFPIhF.js +31 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-BaqWsmrf.js +153 -0
- package/dist/force-state-CCqoTfVB.d.ts +23 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/handler-DtYVCZY6.d.ts +39 -0
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/index-gCZBO53s.d.ts +73 -0
- package/dist/index.d.ts +6 -36
- package/dist/index.js +798 -240
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/marker-C66LxOhJ.d.ts +9 -0
- package/dist/marker-CMrvxPmS.d.ts +12 -0
- package/dist/marker-DjeGvL-F.js +9 -0
- package/dist/marker-uZYPOJ4M.js +12 -0
- package/dist/markers.d.ts +3 -0
- package/dist/markers.js +3 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.d.ts +52 -0
- package/dist/next/config.js +78 -0
- package/dist/next.d.ts +14 -19
- package/dist/next.js +7 -30
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/payload-MUQ9ciER.d.ts +92 -0
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +122 -0
- package/dist/plugins/access/server.js +340 -0
- package/dist/plugins/access.d.ts +41 -0
- package/dist/plugins/access.js +51 -0
- package/dist/plugins/agent/server.d.ts +94 -0
- package/dist/plugins/agent/server.js +455 -0
- package/dist/plugins/agent.d.ts +37 -0
- package/dist/plugins/agent.js +69 -0
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +5 -0
- package/dist/plugins/design.js +4 -0
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +225 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -0
- package/dist/plugins/observe.js +2 -0
- package/dist/plugins/ops/server.d.ts +82 -0
- package/dist/plugins/ops/server.js +381 -0
- package/dist/plugins/ops.d.ts +27 -0
- package/dist/plugins/ops.js +41 -0
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +4 -86
- package/dist/plugins-BZvDqGx5.d.ts +144 -0
- package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.d.ts +181 -0
- package/dist/review.js +1017 -0
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/selector-NSYSe7AZ.js +28 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +3 -39
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/shortcut-s_mjGeU8.js +179 -0
- package/dist/state-CjjZPjPJ.js +40 -0
- package/dist/state-boundary.d.ts +26 -0
- package/dist/state-boundary.js +61 -0
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/store-CQqIIKTc.js +59 -0
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/styles-BA8ueHoV.js +342 -0
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/types-Cxh4twqc.d.ts +50 -0
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-f3jlNxzw.d.ts +92 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +85 -5
- package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
- package/dist/plugins-1QmTmZyL.d.ts +0 -76
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { i as HudMockClientStatus, n as data, r as HudMockClientOptions, t as DataOptions } from "../index-DstI_ike.js";
|
|
2
|
+
import { c as HudMockScenarioInfo, i as HudMockNodeStatus, n as HudMockContext, o as HudMockResolve, r as HudMockMethod, s as HudMockScenario, t as HudMockActive } from "../mocks-CA-wM2SB.js";
|
|
3
|
+
import { n as HudMockWorkerModule, r as MockWorkerOptions, t as HudMockWorkerHandle } from "../msw-browser-wjaYgkB7.js";
|
|
4
|
+
import { c as HudFlagValue, h as readFlagOverrides, n as FLAGS_STORAGE_KEY, o as HudFlagOverride, r as FLAG_KEY, s as HudFlagScope, t as FLAGS_COOKIE, u as flagOverride } from "../flags-DVtaJ8pQ.js";
|
|
5
|
+
import { a as FlagsResponse, c as HudFlagDefinition, d as HudSeedInfo, f as MocksResponse, h as SeedRunResponse, i as FlagOverrideBody, l as HudFlagType, m as RoleSwitchResponse, p as RoleSwitchBody, s as HudAuthUserInfo, t as DataStateResponse } from "../types-Dn68psVz.js";
|
|
6
|
+
export { DataOptions, type DataStateResponse, FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, type FlagOverrideBody, type FlagsResponse, type HudAuthUserInfo, type HudFlagDefinition, type HudFlagOverride, type HudFlagScope, type HudFlagType, type HudFlagValue, type HudMockActive, type HudMockClientOptions, type HudMockClientStatus, type HudMockContext, type HudMockMethod, type HudMockNodeStatus, type HudMockResolve, type HudMockScenario, type HudMockScenarioInfo, type HudMockWorkerHandle, type HudMockWorkerModule, type HudSeedInfo, type MockWorkerOptions, type MocksResponse, type RoleSwitchBody, type RoleSwitchResponse, type SeedRunResponse, data, flagOverride, readFlagOverrides };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { i as definePlugin } from "../plugins-DVy_vaYr.js";
|
|
2
|
+
import { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, flagOverride, readFlagOverrides } from "../flags.js";
|
|
3
|
+
import { a as useDataState, o as configureMockClient } from "../data-store-ChF1td_P.js";
|
|
4
|
+
import { lazy } from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region src/plugins/data/data-pill.tsx
|
|
7
|
+
/** The pill item: who the page is signed in as, how many flags are overridden and how many endpoints are mocked. */
|
|
8
|
+
function DataPill({ ctx }) {
|
|
9
|
+
const state = useDataState(ctx);
|
|
10
|
+
if (state.status !== "ready") return /* @__PURE__ */ jsx(Fragment, { children: "Data" });
|
|
11
|
+
const { auth, flags, mocks } = state.data;
|
|
12
|
+
const overridden = flags?.overrides.length ?? 0;
|
|
13
|
+
const mocked = mocks ? Object.keys(mocks.active).length : 0;
|
|
14
|
+
const who = auth ? auth.current?.label ?? "anonymous" : null;
|
|
15
|
+
const busy = Boolean(auth?.current) || overridden > 0 || mocked > 0;
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17
|
+
/* @__PURE__ */ jsx("span", {
|
|
18
|
+
className: "dot",
|
|
19
|
+
"data-rating": busy ? "needs-improvement" : "good"
|
|
20
|
+
}),
|
|
21
|
+
who ?? "Data",
|
|
22
|
+
overridden > 0 ? ` · ${overridden} flag${overridden === 1 ? "" : "s"}` : "",
|
|
23
|
+
mocked > 0 ? ` · ${mocked} mock${mocked === 1 ? "" : "s"}` : ""
|
|
24
|
+
] });
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/plugins/data/index.tsx
|
|
28
|
+
const Panel = lazy(() => import("../data-panel-DhxAmP91.js"));
|
|
29
|
+
/**
|
|
30
|
+
* Role switch, feature-flag overrides, seeds and mock scenarios. The pill
|
|
31
|
+
* shows who the page is signed in as, how many flags are overridden and how
|
|
32
|
+
* many endpoints are mocked; the panel picks a fixture user (the page
|
|
33
|
+
* reloads signed in as them, through the auth seam on the server), sets
|
|
34
|
+
* overrides in cookie or localStorage scope, runs the app's seed functions
|
|
35
|
+
* and toggles one scenario per endpoint, persisted through the storage seam
|
|
36
|
+
* until reset. Client half; the server half is `dataServer()` from
|
|
37
|
+
* `@hansenexus/hud/plugins/data/server`. Needs `data.write`, which `access`
|
|
38
|
+
* hard-denies on production.
|
|
39
|
+
*/
|
|
40
|
+
function data({ mocks } = {}) {
|
|
41
|
+
configureMockClient(mocks);
|
|
42
|
+
return definePlugin({
|
|
43
|
+
id: "data",
|
|
44
|
+
title: "Data",
|
|
45
|
+
capability: "data.write",
|
|
46
|
+
pill: DataPill,
|
|
47
|
+
panel: Panel
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { FLAGS_COOKIE, FLAGS_STORAGE_KEY, FLAG_KEY, data, flagOverride, readFlagOverrides };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { l as HudRouteContext } from "../../plugins-BZvDqGx5.js";
|
|
2
|
+
import { a as VariantStatus, c as toVariantRecord, i as VariantRecord, n as DecideResponse, o as VariantsListResponse, r as VARIANTS_COLLECTION, s as recordKey, t as DecideBody } from "../../variants-types-CcRf119M.js";
|
|
3
|
+
import { n as DispatchProvider } from "../../types-szkr2QOF.js";
|
|
4
|
+
import { t as HudStore } from "../../types-DaJcsEjO.js";
|
|
5
|
+
import "../../server.js";
|
|
6
|
+
//#region src/plugins/design/server.d.ts
|
|
7
|
+
export interface VariantDecision {
|
|
8
|
+
group: string;
|
|
9
|
+
label: string;
|
|
10
|
+
winner: {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
};
|
|
14
|
+
losers: {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
decidedAt: string;
|
|
19
|
+
}
|
|
20
|
+
export interface VariantsServerOptions {
|
|
21
|
+
/** Where scores and decisions live. `file()` keeps them in `.hud/variants.json`. */
|
|
22
|
+
store: HudStore;
|
|
23
|
+
/**
|
|
24
|
+
* The dispatch seam: Decide queues a cleanup brief here (`claudeCode()`,
|
|
25
|
+
* `hermes()` from `@hansenexus/hud/plugins/agent/server`, or anything with
|
|
26
|
+
* the same shape). Without it a decision is recorded and nothing is queued.
|
|
27
|
+
*/
|
|
28
|
+
dispatch?: DispatchProvider;
|
|
29
|
+
/** The brief's text. Default: `cleanupBrief`. */
|
|
30
|
+
brief?: (decision: VariantDecision) => string;
|
|
31
|
+
}
|
|
32
|
+
/** The cleanup brief Decide hands the dispatch seam. */
|
|
33
|
+
export declare function cleanupBrief({ group, label, winner, losers, decidedAt }: VariantDecision): string;
|
|
34
|
+
/**
|
|
35
|
+
* Server half of `variants()`: `GET /` lists every record of the store's
|
|
36
|
+
* `variants` collection, `POST /:group/decide` marks a winner (`decidedAt`,
|
|
37
|
+
* `status: "decided"`; the others `rejected`) through the storage seam and
|
|
38
|
+
* queues a cleanup brief through the dispatch seam. Carries `variants.decide`,
|
|
39
|
+
* which only development grants by default.
|
|
40
|
+
*/
|
|
41
|
+
export declare function variantsServer({ store, dispatch, brief }: VariantsServerOptions): {
|
|
42
|
+
readonly id: "variants";
|
|
43
|
+
readonly capability: "variants.decide";
|
|
44
|
+
readonly routes: {
|
|
45
|
+
readonly "/": {
|
|
46
|
+
GET: () => Promise<Response>;
|
|
47
|
+
};
|
|
48
|
+
readonly "/:group/decide": {
|
|
49
|
+
readonly POST: (request: Request, { params }: HudRouteContext) => Promise<Response>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { type DecideBody, type DecideResponse, VARIANTS_COLLECTION, type VariantRecord, type VariantStatus, type VariantsListResponse, recordKey, toVariantRecord };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { i as definePlugin } from "../../plugins-DVy_vaYr.js";
|
|
2
|
+
import { t as refuseCrossSite } from "../../same-origin-BGet22CC.js";
|
|
3
|
+
import { t as HudStoreError } from "../../types-BIkI-qN8.js";
|
|
4
|
+
//#region src/plugins/design/variants-types.ts
|
|
5
|
+
/** Wire types shared by the Variants panel and `variantsServer()`. */
|
|
6
|
+
/** The store collection scores and decisions live in: `.hud/variants.json` with `file()`. */
|
|
7
|
+
const VARIANTS_COLLECTION = "variants";
|
|
8
|
+
function recordKey(group, id) {
|
|
9
|
+
return `${group}:${id}`;
|
|
10
|
+
}
|
|
11
|
+
function isRecord$1(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
const STATUSES = [
|
|
15
|
+
"open",
|
|
16
|
+
"decided",
|
|
17
|
+
"rejected"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* A store entry as a `VariantRecord`: group and id come from the fields, or
|
|
21
|
+
* from a `<group>:<id>` key when the file omits them. Unknown fields are
|
|
22
|
+
* dropped, wrong types ignored; null when neither names the variant.
|
|
23
|
+
*/
|
|
24
|
+
function toVariantRecord(id, value) {
|
|
25
|
+
if (!isRecord$1(value)) return null;
|
|
26
|
+
const separator = id.indexOf(":");
|
|
27
|
+
const group = typeof value.group === "string" ? value.group : separator > 0 ? id.slice(0, separator) : "";
|
|
28
|
+
const variant = typeof value.id === "string" ? value.id : separator > 0 ? id.slice(separator + 1) : "";
|
|
29
|
+
if (!group || !variant) return null;
|
|
30
|
+
const record = {
|
|
31
|
+
group,
|
|
32
|
+
id: variant
|
|
33
|
+
};
|
|
34
|
+
if (typeof value.label === "string") record.label = value.label;
|
|
35
|
+
if (typeof value.status === "string" && STATUSES.includes(value.status)) record.status = value.status;
|
|
36
|
+
if (typeof value.score === "number" && Number.isFinite(value.score)) record.score = value.score;
|
|
37
|
+
if (typeof value.rationale === "string") record.rationale = value.rationale;
|
|
38
|
+
if (typeof value.scoredBy === "string") record.scoredBy = value.scoredBy;
|
|
39
|
+
if (typeof value.decidedAt === "string") record.decidedAt = value.decidedAt;
|
|
40
|
+
return record;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/plugins/design/server.ts
|
|
44
|
+
const NO_STORE = { "cache-control": "no-store" };
|
|
45
|
+
function isRecord(value) {
|
|
46
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
function message(error) {
|
|
49
|
+
return error instanceof Error ? error.message : String(error);
|
|
50
|
+
}
|
|
51
|
+
function failed(error, what) {
|
|
52
|
+
if (error instanceof HudStoreError) return Response.json({
|
|
53
|
+
ok: false,
|
|
54
|
+
error: error.message
|
|
55
|
+
}, { status: error.status });
|
|
56
|
+
console.error(`hud variants: ${what} failed`, error);
|
|
57
|
+
return Response.json({
|
|
58
|
+
ok: false,
|
|
59
|
+
error: `${what} failed`
|
|
60
|
+
}, { status: 500 });
|
|
61
|
+
}
|
|
62
|
+
function parseDecide(value) {
|
|
63
|
+
if (!isRecord(value) || typeof value.id !== "string" || !value.id) return null;
|
|
64
|
+
const body = { id: value.id };
|
|
65
|
+
if (typeof value.label === "string") body.label = value.label;
|
|
66
|
+
if (Array.isArray(value.variants)) body.variants = value.variants.flatMap((v) => isRecord(v) && typeof v.id === "string" && v.id ? [{
|
|
67
|
+
id: v.id,
|
|
68
|
+
label: typeof v.label === "string" ? v.label : v.id
|
|
69
|
+
}] : []);
|
|
70
|
+
return body;
|
|
71
|
+
}
|
|
72
|
+
const quote = (v) => v.label === v.id ? `"${v.id}"` : `"${v.id}" (${v.label})`;
|
|
73
|
+
/** The cleanup brief Decide hands the dispatch seam. */
|
|
74
|
+
function cleanupBrief({ group, label, winner, losers, decidedAt }) {
|
|
75
|
+
const name = label === group ? `"${group}"` : `"${group}" (${label})`;
|
|
76
|
+
const remove = losers.length > 0 ? `remove ${losers.map(quote).join(", ")}` : "there are no other variants";
|
|
77
|
+
return [
|
|
78
|
+
`Variant group ${name} was decided on ${decidedAt}: keep ${quote(winner)}, ${remove}.`,
|
|
79
|
+
"",
|
|
80
|
+
`Task: find <VariantGroup id="${group}"> in the app, inline the winning variant's markup where the group renders, delete the losing variants and the VariantGroup wrapper, remove the group's entries from .hud/variants.json, and run the project's checks.`
|
|
81
|
+
].join("\n");
|
|
82
|
+
}
|
|
83
|
+
async function listRecords(store) {
|
|
84
|
+
return (await store.list(VARIANTS_COLLECTION)).flatMap((entry) => {
|
|
85
|
+
const record = toVariantRecord(entry.id, entry.value);
|
|
86
|
+
return record ? [record] : [];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Server half of `variants()`: `GET /` lists every record of the store's
|
|
91
|
+
* `variants` collection, `POST /:group/decide` marks a winner (`decidedAt`,
|
|
92
|
+
* `status: "decided"`; the others `rejected`) through the storage seam and
|
|
93
|
+
* queues a cleanup brief through the dispatch seam. Carries `variants.decide`,
|
|
94
|
+
* which only development grants by default.
|
|
95
|
+
*/
|
|
96
|
+
function variantsServer({ store, dispatch, brief = cleanupBrief }) {
|
|
97
|
+
return definePlugin({
|
|
98
|
+
id: "variants",
|
|
99
|
+
capability: "variants.decide",
|
|
100
|
+
routes: {
|
|
101
|
+
"/": { GET: async () => {
|
|
102
|
+
try {
|
|
103
|
+
const body = {
|
|
104
|
+
ok: true,
|
|
105
|
+
records: await listRecords(store)
|
|
106
|
+
};
|
|
107
|
+
return Response.json(body, { headers: NO_STORE });
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return failed(error, "list");
|
|
110
|
+
}
|
|
111
|
+
} },
|
|
112
|
+
"/:group/decide": { POST: async (request, { params }) => {
|
|
113
|
+
const refusal = refuseCrossSite(request);
|
|
114
|
+
if (refusal) return refusal;
|
|
115
|
+
const group = params.group ?? "";
|
|
116
|
+
const body = parseDecide(await request.json().catch(() => null));
|
|
117
|
+
if (!group || !body) return Response.json({
|
|
118
|
+
ok: false,
|
|
119
|
+
error: "invalid decision"
|
|
120
|
+
}, { status: 400 });
|
|
121
|
+
try {
|
|
122
|
+
const existing = (await listRecords(store)).filter((r) => r.group === group);
|
|
123
|
+
const byId = new Map(existing.map((r) => [r.id, r]));
|
|
124
|
+
const known = /* @__PURE__ */ new Map();
|
|
125
|
+
for (const r of existing) known.set(r.id, r.label ?? r.id);
|
|
126
|
+
for (const v of body.variants ?? []) known.set(v.id, v.label);
|
|
127
|
+
if (!known.has(body.id)) known.set(body.id, body.id);
|
|
128
|
+
const decidedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
129
|
+
for (const [id, label] of known) {
|
|
130
|
+
const { decidedAt: _previous, ...rest } = byId.get(id) ?? {
|
|
131
|
+
group,
|
|
132
|
+
id
|
|
133
|
+
};
|
|
134
|
+
const record = id === body.id ? {
|
|
135
|
+
...rest,
|
|
136
|
+
group,
|
|
137
|
+
id,
|
|
138
|
+
label,
|
|
139
|
+
status: "decided",
|
|
140
|
+
decidedAt
|
|
141
|
+
} : {
|
|
142
|
+
...rest,
|
|
143
|
+
group,
|
|
144
|
+
id,
|
|
145
|
+
label,
|
|
146
|
+
status: "rejected"
|
|
147
|
+
};
|
|
148
|
+
await store.set(VARIANTS_COLLECTION, recordKey(group, id), { ...record });
|
|
149
|
+
}
|
|
150
|
+
const winnerLabel = known.get(body.id) ?? body.id;
|
|
151
|
+
const decision = {
|
|
152
|
+
group,
|
|
153
|
+
label: body.label ?? group,
|
|
154
|
+
winner: {
|
|
155
|
+
id: body.id,
|
|
156
|
+
label: winnerLabel
|
|
157
|
+
},
|
|
158
|
+
losers: [...known].filter(([id]) => id !== body.id).map(([id, label]) => ({
|
|
159
|
+
id,
|
|
160
|
+
label
|
|
161
|
+
})),
|
|
162
|
+
decidedAt
|
|
163
|
+
};
|
|
164
|
+
const response = {
|
|
165
|
+
ok: true,
|
|
166
|
+
group,
|
|
167
|
+
id: body.id,
|
|
168
|
+
decidedAt,
|
|
169
|
+
queued: null
|
|
170
|
+
};
|
|
171
|
+
if (dispatch) try {
|
|
172
|
+
const status = await dispatch.status?.() ?? { available: true };
|
|
173
|
+
if (!status.available) throw new Error(status.reason);
|
|
174
|
+
const prompt = brief(decision);
|
|
175
|
+
const run = await dispatch.dispatch({
|
|
176
|
+
note: `Clean up variant group "${group}": keep "${body.id}"`,
|
|
177
|
+
payload: null,
|
|
178
|
+
hints: [],
|
|
179
|
+
prompt
|
|
180
|
+
});
|
|
181
|
+
response.queued = {
|
|
182
|
+
target: dispatch.id,
|
|
183
|
+
runId: run.runId
|
|
184
|
+
};
|
|
185
|
+
if (run.detail) response.queued.detail = run.detail;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
response.queueError = message(error);
|
|
188
|
+
}
|
|
189
|
+
return Response.json(response);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
return failed(error, "decide");
|
|
192
|
+
}
|
|
193
|
+
} }
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { VARIANTS_COLLECTION, cleanupBrief, recordKey, toVariantRecord, variantsServer };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { a as HudGenerateResult, c as HudTokenDescriptor, d as HudTokensAdapter, i as HudGenerateRequest, l as HudTokenGroup, n as tokens, o as HudVariantCategory, r as variants, s as HudVariantsAdapter, t as forceState, u as HudTokenScope } from "../index-Hhh7OXzU.js";
|
|
2
|
+
import { a as formatVariantParam, i as VariantOption, n as VARIANT_PARAM, o as parseVariantParam, r as VariantGroupInfo, t as VARIANT_MARKER } from "../variant-groups-aAIrcNK5.js";
|
|
3
|
+
import { a as VariantStatus, i as VariantRecord, n as DecideResponse, o as VariantsListResponse, t as DecideBody } from "../variants-types-CcRf119M.js";
|
|
4
|
+
import { i as ForcedState, n as FORCE_STATE_MARKER, r as FORCE_STATE_PARAM, t as FORCED_STATES } from "../force-state-CCqoTfVB.js";
|
|
5
|
+
export { type DecideBody, type DecideResponse, FORCED_STATES, FORCE_STATE_MARKER, FORCE_STATE_PARAM, type ForcedState, type HudGenerateRequest, type HudGenerateResult, type HudTokenDescriptor, type HudTokenGroup, type HudTokenScope, type HudTokensAdapter, type HudVariantCategory, type HudVariantsAdapter, VARIANT_MARKER, VARIANT_PARAM, type VariantGroupInfo, type VariantOption, type VariantRecord, type VariantStatus, type VariantsListResponse, forceState, formatVariantParam, parseVariantParam, tokens, variants };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as FORCE_STATE_MARKER, r as FORCE_STATE_PARAM, t as FORCED_STATES } from "../force-state-BaqWsmrf.js";
|
|
2
|
+
import { n as tokens, r as variants, t as forceState } from "../design-D0kGgPoP.js";
|
|
3
|
+
import { n as VARIANT_PARAM, o as parseVariantParam, r as formatVariantParam, t as VARIANT_MARKER } from "../variant-groups-TIfO3NIj.js";
|
|
4
|
+
export { FORCED_STATES, FORCE_STATE_MARKER, FORCE_STATE_PARAM, VARIANT_MARKER, VARIANT_PARAM, forceState, formatVariantParam, parseVariantParam, tokens, variants };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ConvexQueryEntry, i as ConvexCall, n as InspectConvexOptions, o as ConvexSnapshot, r as inspectConvex, t as ConvexClientLike } from "../../index-BJ26pse9.js";
|
|
2
|
+
export { type ConvexCall, ConvexClientLike, type ConvexQueryEntry, type ConvexSnapshot, InspectConvexOptions, inspectConvex };
|