@laoyuehanni/dsh-token-usage 0.4.14 → 0.4.15

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/lib/client.js CHANGED
@@ -1953,88 +1953,6 @@ window.__ModuleLoader__.load({
1953
1953
  easing: "cubic-bezier(0.25, 0.85, 0.35, 1)"
1954
1954
  });
1955
1955
  }
1956
- /** +Δ label fall (`deltaFall`). Caller must position the element (absolute,
1957
- * below the pill — the dock sits under the composer, so the label falls
1958
- * away from the message scrollport rather than climbing into it). */
1959
- function runDeltaFly(el, v) {
1960
- if (!motionAllowed() || !waapiAvailable(el)) return null;
1961
- return el.animate([
1962
- {
1963
- opacity: 0,
1964
- transform: "translate(-50%, 20%)"
1965
- },
1966
- {
1967
- opacity: 1,
1968
- transform: "translate(-50%, 20%)",
1969
- offset: .15
1970
- },
1971
- {
1972
- opacity: 0,
1973
- transform: `translate(calc(-50% + ${v.flyX}), calc(100% + ${v.flyY}))`
1974
- }
1975
- ], {
1976
- duration: v.inflateMs,
1977
- easing: "cubic-bezier(0.22, 0.55, 0.25, 1)",
1978
- fill: "both"
1979
- });
1980
- }
1981
- // \0dsh-css:/home/runner/work/dsh-token-usage/dsh-token-usage/src/client/CostPill.module.css.mjs
1982
- const css$15 = ".T_i-_W_root{min-width:0;display:inline-flex;position:relative}.T_i-_W_pill{box-sizing:border-box;max-width:100%;color:var(--dsw-alias-label-tertiary);font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));font-variant-numeric:tabular-nums;white-space:nowrap;background:0 0;border:none;border-radius:999px;align-items:center;gap:6px;padding:1px 8px;display:inline-flex}.T_i-_W_glyph{flex:none;width:14px;height:14px}button.T_i-_W_pill{cursor:pointer}button.T_i-_W_pill:hover,button.T_i-_W_pill[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}.T_i-_W_cost{transform-origin:50%;z-index:2;display:inline-flex;position:relative}.T_i-_W_deltaLayer{pointer-events:none;z-index:3;position:absolute;inset:0;overflow:visible}.T_i-_W_deltaFly{color:var(--dsw-alias-state-warn-primary);font-variant-numeric:tabular-nums;white-space:nowrap;pointer-events:none;text-shadow:0 0 8px color-mix(in srgb, var(--dsw-alias-state-warn-primary) 35%, transparent);margin-top:2px;font-size:11px;font-weight:600;position:absolute;top:100%;left:50%}@media (prefers-reduced-motion:reduce){.T_i-_W_deltaFly{display:none}}.T_i-_W_panel{background:var(--dsw-specific-menu);width:300px;backdrop-filter:var(--dsw-menu-backdrop-filter);border:1px solid var(--dsw-alias-border-inverted);box-shadow:var(--dsw-shadow-lv3);z-index:30;font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);color:var(--dsw-alias-label-primary);border-radius:12px;padding:12px 14px;position:absolute;bottom:calc(100% + 8px)}.T_i-_W_panelHead{border-bottom:1px solid var(--dsw-alias-border-l1);justify-content:space-between;align-items:baseline;padding-bottom:8px;display:flex}.T_i-_W_panelTitle{align-items:center;gap:6px;font-weight:600;display:inline-flex}.T_i-_W_scopeTag{color:var(--dsw-alias-label-secondary);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:1px 5px;font-size:10px;font-weight:400}.T_i-_W_panelTotal{font-variant-numeric:tabular-nums;font-size:14px;font-weight:600}.T_i-_W_usageLine{font-variant-numeric:tabular-nums;align-items:center;gap:6px;margin-top:8px;display:flex}.T_i-_W_dot{color:var(--dsw-alias-separator-primary)}.T_i-_W_rows{flex-direction:column;margin-top:8px;display:flex}.T_i-_W_row{font-variant-numeric:tabular-nums;justify-content:space-between;padding:4px 0;display:flex}.T_i-_W_rowLabel{color:var(--dsw-alias-label-secondary);align-items:center;gap:6px;display:inline-flex}.T_i-_W_rowValue{color:var(--dsw-alias-label-primary)}.T_i-_W_rowSub .T_i-_W_rowValue{color:var(--dsw-alias-label-secondary)}.T_i-_W_tok{color:var(--dsw-alias-label-tertiary);margin-left:6px;font-size:11px}.T_i-_W_groupLabel{color:var(--dsw-alias-label-tertiary);letter-spacing:.06em;margin-top:10px;font-size:10px}.T_i-_W_requests{color:var(--dsw-alias-label-tertiary);font-size:11px}.T_i-_W_unpriced .T_i-_W_rowLabel,.T_i-_W_unpriced .T_i-_W_rowValue{color:var(--dsw-alias-label-tertiary);font-style:italic}.T_i-_W_pending{color:var(--dsw-alias-label-tertiary)}";
1983
- const tagId$15 = "@laoyuehanni/dsh-token-usage/CostPill.module.css";
1984
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$15) + "]") === null) {
1985
- const tag = document.createElement("style");
1986
- tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
1987
- tag.dataset.pluginCss = tagId$15;
1988
- tag.textContent = css$15;
1989
- document.head.appendChild(tag);
1990
- }
1991
- var CostPill_module_css_default = {
1992
- "cost": "T_i-_W_cost",
1993
- "deltaFly": "T_i-_W_deltaFly",
1994
- "deltaLayer": "T_i-_W_deltaLayer",
1995
- "dot": "T_i-_W_dot",
1996
- "glyph": "T_i-_W_glyph",
1997
- "groupLabel": "T_i-_W_groupLabel",
1998
- "panel": "T_i-_W_panel",
1999
- "panelHead": "T_i-_W_panelHead",
2000
- "panelTitle": "T_i-_W_panelTitle",
2001
- "panelTotal": "T_i-_W_panelTotal",
2002
- "pending": "T_i-_W_pending",
2003
- "pill": "T_i-_W_pill",
2004
- "requests": "T_i-_W_requests",
2005
- "root": "T_i-_W_root",
2006
- "row": "T_i-_W_row",
2007
- "rowLabel": "T_i-_W_rowLabel",
2008
- "rowSub": "T_i-_W_rowSub",
2009
- "rowValue": "T_i-_W_rowValue",
2010
- "rows": "T_i-_W_rows",
2011
- "scopeTag": "T_i-_W_scopeTag",
2012
- "tok": "T_i-_W_tok",
2013
- "unpriced": "T_i-_W_unpriced",
2014
- "usageLine": "T_i-_W_usageLine"
2015
- };
2016
- // src/client/CostDeltaFlyLabel.tsx
2017
- /** One +Δ fly label; animation starts on mount via WAAPI. */
2018
- function CostDeltaFlyLabel({ text, vars }) {
2019
- const ref = (0, react.useRef)(null);
2020
- (0, react.useLayoutEffect)(() => {
2021
- const el = ref.current;
2022
- if (el === null) return;
2023
- const anim = runDeltaFly(el, vars);
2024
- if (anim === null) {
2025
- el.style.visibility = "hidden";
2026
- return;
2027
- }
2028
- return () => {
2029
- anim.cancel();
2030
- };
2031
- }, [vars]);
2032
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2033
- ref,
2034
- className: CostPill_module_css_default["deltaFly"],
2035
- children: text
2036
- });
2037
- }
2038
1956
  // src/client/cost-inflate.ts
2039
1957
  const MISS_RATE_CAP = .55;
2040
1958
  const OUT_CAP = 32e3;
@@ -2070,16 +1988,15 @@ window.__ModuleLoader__.load({
2070
1988
  return {
2071
1989
  inflateMs: Math.round(lerp(1e3, 1800, I)),
2072
1990
  popScale: lerp(1.08, 1.32, I).toFixed(3),
2073
- warnMix: `${Math.round(lerp(0, 55, I))}%`,
2074
- flyY: `${lerp(22, 38, I).toFixed(1)}px`,
2075
- flyX: `${((Math.random() - .5) * 10).toFixed(1)}px`
1991
+ warnMix: `${Math.round(lerp(0, 55, I))}%`
2076
1992
  };
2077
1993
  }
2078
1994
  // src/client/use-cost-inflate.ts
2079
1995
  /**
2080
1996
  * Request-driven cost-figure inflate animation for the composer-dock usage
2081
- * pill: detects new usage from summary deltas and drives WAAPI motion on
2082
- * the cost figure and ephemeral +Δ fly labels.
1997
+ * pill: detects new usage from summary deltas and drives the WAAPI motion on
1998
+ * the cost figure (a scale + colour pop whose amplitude follows the step's
1999
+ * token intensity).
2083
2000
  *
2084
2001
  * @module token-usage/client/use-cost-inflate
2085
2002
  */
@@ -2091,44 +2008,23 @@ window.__ModuleLoader__.load({
2091
2008
  return totalTokens$1(delta) > 0;
2092
2009
  }
2093
2010
  /**
2094
- * Hook the pill uses to play costPop + deltaFall on each new request.
2011
+ * Hook the pill uses to play the costPop on each new request.
2095
2012
  * @param scopeKey - changes reset the diff baseline.
2096
2013
  * @param costRef - the live cost figure span (WAAPI target).
2097
2014
  */
2098
2015
  function useCostInflate(scopeKey, costRef) {
2099
2016
  const prevRef = (0, react.useRef)(null);
2100
- const flyIdRef = (0, react.useRef)(0);
2101
- const timersRef = (0, react.useRef)([]);
2102
- const flyCountRef = (0, react.useRef)(0);
2103
2017
  const popAnimRef = (0, react.useRef)(null);
2104
- const [flies, setFlies] = (0, react.useState)([]);
2105
- const [flyOverflow, setFlyOverflow] = (0, react.useState)(false);
2106
- const clearTimers = (0, react.useCallback)(() => {
2107
- for (const id of timersRef.current) window.clearTimeout(id);
2108
- timersRef.current = [];
2109
- }, []);
2110
- const schedule = (0, react.useCallback)((fn, ms) => {
2111
- const id = window.setTimeout(fn, ms);
2112
- timersRef.current.push(id);
2113
- }, []);
2114
2018
  const reset = (0, react.useCallback)(() => {
2115
- clearTimers();
2116
2019
  popAnimRef.current?.cancel();
2117
2020
  popAnimRef.current = null;
2118
2021
  prevRef.current = null;
2119
- flyIdRef.current = 0;
2120
- flyCountRef.current = 0;
2121
- setFlies([]);
2122
- setFlyOverflow(false);
2123
- }, [clearTimers]);
2022
+ }, []);
2124
2023
  (0, react.useEffect)(() => {
2125
2024
  reset();
2126
2025
  }, [scopeKey, reset]);
2127
2026
  (0, react.useEffect)(() => () => {
2128
- clearTimers();
2129
- }, [clearTimers]);
2130
- const maybeClearOverflow = (0, react.useCallback)(() => {
2131
- if (flyCountRef.current <= 0) setFlyOverflow(false);
2027
+ popAnimRef.current?.cancel();
2132
2028
  }, []);
2133
2029
  const playCostPop = (0, react.useCallback)((v) => {
2134
2030
  const el = costRef.current;
@@ -2137,8 +2033,6 @@ window.__ModuleLoader__.load({
2137
2033
  popAnimRef.current = runCostPop(el, v);
2138
2034
  }, [costRef]);
2139
2035
  return {
2140
- flies,
2141
- flyOverflow,
2142
2036
  onSummary: (0, react.useCallback)((summary) => {
2143
2037
  if (!costsAvailable(summary.costState)) {
2144
2038
  reset();
@@ -2154,36 +2048,46 @@ window.__ModuleLoader__.load({
2154
2048
  if (!hasUsageChurn(prev, summary)) return;
2155
2049
  if (!motionAllowed()) return;
2156
2050
  const v = animVars(computeIntensityFromDelta(deltaTotals(prev.totals, summary.total)));
2157
- setFlyOverflow(true);
2158
2051
  window.requestAnimationFrame(() => {
2159
2052
  playCostPop(v);
2160
2053
  });
2161
- const wireDeltaCost = summary.totalCost - prev.totalCost;
2162
- if (wireDeltaCost > MIN_WIRE_DELTA_COST) {
2163
- const view = currencyViewOf(summary);
2164
- const text = `+${(wireDeltaCost / view.rate).toFixed(2)}${view.symbol}`;
2165
- const id = ++flyIdRef.current;
2166
- flyCountRef.current += 1;
2167
- setFlies((current) => [...current, {
2168
- id,
2169
- text,
2170
- vars: v
2171
- }]);
2172
- schedule(() => {
2173
- flyCountRef.current -= 1;
2174
- setFlies((current) => current.filter((fly) => fly.id !== id));
2175
- maybeClearOverflow();
2176
- }, v.inflateMs + 40);
2177
- } else schedule(maybeClearOverflow, v.inflateMs + 40);
2178
- }, [
2179
- maybeClearOverflow,
2180
- playCostPop,
2181
- schedule,
2182
- reset
2183
- ]),
2054
+ }, [playCostPop, reset]),
2184
2055
  reset
2185
2056
  };
2186
2057
  }
2058
+ // \0dsh-css:/home/runner/work/dsh-token-usage/dsh-token-usage/src/client/CostPill.module.css.mjs
2059
+ const css$15 = ".T_i-_W_root{min-width:0;display:inline-flex;position:relative}.T_i-_W_pill{box-sizing:border-box;max-width:100%;color:var(--dsw-alias-label-tertiary);font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));font-variant-numeric:tabular-nums;white-space:nowrap;background:0 0;border:none;border-radius:999px;align-items:center;gap:6px;padding:1px 8px;display:inline-flex}.T_i-_W_glyph{flex:none;width:14px;height:14px}button.T_i-_W_pill{cursor:pointer}button.T_i-_W_pill:hover,button.T_i-_W_pill[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}.T_i-_W_cost{transform-origin:50%;z-index:2;display:inline-flex;position:relative}.T_i-_W_panel{background:var(--dsw-specific-menu);width:300px;backdrop-filter:var(--dsw-menu-backdrop-filter);border:1px solid var(--dsw-alias-border-inverted);box-shadow:var(--dsw-shadow-lv3);z-index:30;font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);color:var(--dsw-alias-label-primary);border-radius:12px;padding:12px 14px;position:absolute;bottom:calc(100% + 8px)}.T_i-_W_panelHead{border-bottom:1px solid var(--dsw-alias-border-l1);justify-content:space-between;align-items:baseline;padding-bottom:8px;display:flex}.T_i-_W_panelTitle{align-items:center;gap:6px;font-weight:600;display:inline-flex}.T_i-_W_scopeTag{color:var(--dsw-alias-label-secondary);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:1px 5px;font-size:10px;font-weight:400}.T_i-_W_panelTotal{font-variant-numeric:tabular-nums;font-size:14px;font-weight:600}.T_i-_W_usageLine{font-variant-numeric:tabular-nums;align-items:center;gap:6px;margin-top:8px;display:flex}.T_i-_W_dot{color:var(--dsw-alias-separator-primary)}.T_i-_W_rows{flex-direction:column;margin-top:8px;display:flex}.T_i-_W_row{font-variant-numeric:tabular-nums;justify-content:space-between;padding:4px 0;display:flex}.T_i-_W_rowLabel{color:var(--dsw-alias-label-secondary);align-items:center;gap:6px;display:inline-flex}.T_i-_W_rowValue{color:var(--dsw-alias-label-primary)}.T_i-_W_rowSub .T_i-_W_rowValue{color:var(--dsw-alias-label-secondary)}.T_i-_W_tok{color:var(--dsw-alias-label-tertiary);margin-left:6px;font-size:11px}.T_i-_W_groupLabel{color:var(--dsw-alias-label-tertiary);letter-spacing:.06em;margin-top:10px;font-size:10px}.T_i-_W_requests{color:var(--dsw-alias-label-tertiary);font-size:11px}.T_i-_W_unpriced .T_i-_W_rowLabel,.T_i-_W_unpriced .T_i-_W_rowValue{color:var(--dsw-alias-label-tertiary);font-style:italic}.T_i-_W_pending{color:var(--dsw-alias-label-tertiary)}";
2060
+ const tagId$15 = "@laoyuehanni/dsh-token-usage/CostPill.module.css";
2061
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$15) + "]") === null) {
2062
+ const tag = document.createElement("style");
2063
+ tag.dataset.plugin = "@laoyuehanni/dsh-token-usage";
2064
+ tag.dataset.pluginCss = tagId$15;
2065
+ tag.textContent = css$15;
2066
+ document.head.appendChild(tag);
2067
+ }
2068
+ var CostPill_module_css_default = {
2069
+ "cost": "T_i-_W_cost",
2070
+ "dot": "T_i-_W_dot",
2071
+ "glyph": "T_i-_W_glyph",
2072
+ "groupLabel": "T_i-_W_groupLabel",
2073
+ "panel": "T_i-_W_panel",
2074
+ "panelHead": "T_i-_W_panelHead",
2075
+ "panelTitle": "T_i-_W_panelTitle",
2076
+ "panelTotal": "T_i-_W_panelTotal",
2077
+ "pending": "T_i-_W_pending",
2078
+ "pill": "T_i-_W_pill",
2079
+ "requests": "T_i-_W_requests",
2080
+ "root": "T_i-_W_root",
2081
+ "row": "T_i-_W_row",
2082
+ "rowLabel": "T_i-_W_rowLabel",
2083
+ "rowSub": "T_i-_W_rowSub",
2084
+ "rowValue": "T_i-_W_rowValue",
2085
+ "rows": "T_i-_W_rows",
2086
+ "scopeTag": "T_i-_W_scopeTag",
2087
+ "tok": "T_i-_W_tok",
2088
+ "unpriced": "T_i-_W_unpriced",
2089
+ "usageLine": "T_i-_W_usageLine"
2090
+ };
2187
2091
  // src/client/CostPill.tsx
2188
2092
  /**
2189
2093
  * Composer-dock usage pill (browser half): a cost trigger registered into
@@ -2208,10 +2112,9 @@ window.__ModuleLoader__.load({
2208
2112
  * cadence, inherited whole): `sessionStats` projection churn plus mirror
2209
2113
  * `updatedAt` is debounced 250 ms into one fetch, a failed FIRST fetch
2210
2114
  * retries itself on a 3 s cadence, and later failures keep the prior
2211
- * figures. When cost rises on a new request the figure plays `costPop`
2212
- * and a +Δ label FALLS below the pill (the dock sits under the composer;
2213
- * the header chip's upward rise would climb into the message scrollport).
2214
- * Reduced-motion users get silent figure updates.
2115
+ * figures. When usage grows on a new request the figure plays `costPop` —
2116
+ * a scale + colour pop whose amplitude follows that step's token
2117
+ * intensity. Reduced-motion users get silent figure updates.
2215
2118
  *
2216
2119
  * Visibility contract: a session with no recorded requests renders
2217
2120
  * nothing; a transient fetch miss keeps the previous render.
@@ -2273,7 +2176,7 @@ window.__ModuleLoader__.load({
2273
2176
  liveSessionStats: useProjection("sessionStats")
2274
2177
  });
2275
2178
  const debouncedKey = useDebouncedValue(`${scopeIds.join("\n")}\n\t${freshnessKey}`, REFRESH_DEBOUNCE_MS$1);
2276
- const { flies, onSummary } = useCostInflate(scopeIds.join("\n"), costRef);
2179
+ const { onSummary } = useCostInflate(scopeIds.join("\n"), costRef);
2277
2180
  const [treeRes, retryTree] = useAsyncResource((signal) => {
2278
2181
  const [idsPart] = debouncedKey.split("\n ");
2279
2182
  return fetchSummary$1((idsPart ?? "").split("\n").filter((id) => id !== ""), "chip", signal);
@@ -2381,41 +2284,30 @@ window.__ModuleLoader__.load({
2381
2284
  onClick: () => {
2382
2285
  setOpen(!open);
2383
2286
  },
2384
- children: [
2385
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
2386
- className: CostPill_module_css_default.glyph,
2387
- viewBox: "0 0 14 14",
2388
- width: "14",
2389
- height: "14",
2390
- "aria-hidden": true,
2391
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
2392
- cx: "7",
2393
- cy: "7",
2394
- r: "5.5",
2395
- fill: "none",
2396
- stroke: "currentColor",
2397
- strokeWidth: "1.2"
2398
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
2399
- d: "M4.8 4.5 L7 7.2 L9.2 4.5 M7 7.2 V10 M5.2 8 H8.8 M5.2 9.4 H8.8",
2400
- fill: "none",
2401
- stroke: "currentColor",
2402
- strokeWidth: "1.2"
2403
- })]
2404
- }),
2405
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2406
- ref: costRef,
2407
- className: CostPill_module_css_default.cost,
2408
- children: costText
2409
- }),
2410
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2411
- className: CostPill_module_css_default.deltaLayer,
2412
- "aria-hidden": "true",
2413
- children: flies.map((fly) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostDeltaFlyLabel, {
2414
- text: fly.text,
2415
- vars: fly.vars
2416
- }, fly.id))
2417
- })
2418
- ]
2287
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
2288
+ className: CostPill_module_css_default.glyph,
2289
+ viewBox: "0 0 14 14",
2290
+ width: "14",
2291
+ height: "14",
2292
+ "aria-hidden": true,
2293
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
2294
+ cx: "7",
2295
+ cy: "7",
2296
+ r: "5.5",
2297
+ fill: "none",
2298
+ stroke: "currentColor",
2299
+ strokeWidth: "1.2"
2300
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
2301
+ d: "M4.8 4.5 L7 7.2 L9.2 4.5 M7 7.2 V10 M5.2 8 H8.8 M5.2 9.4 H8.8",
2302
+ fill: "none",
2303
+ stroke: "currentColor",
2304
+ strokeWidth: "1.2"
2305
+ })]
2306
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2307
+ ref: costRef,
2308
+ className: CostPill_module_css_default.cost,
2309
+ children: costText
2310
+ })]
2419
2311
  }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2420
2312
  className: CostPill_module_css_default.panel,
2421
2313
  role: "dialog",