@wrongstack/webui 0.77.0 → 0.84.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -236,13 +236,18 @@ function createDefaultContainer(opts) {
236
236
  }
237
237
  container.bind(
238
238
  TOKENS.PermissionPolicy,
239
- () => new DefaultPermissionPolicy({
240
- trustFile: wpaths.projectTrust,
241
- yolo: opts.permission?.yolo ?? false,
242
- yoloDestructive: opts.permission?.yoloDestructive ?? opts.permission?.forceAllYolo ?? false,
243
- confirmDestructive: opts.permission?.confirmDestructive ?? false,
244
- promptDelegate: opts.permission?.promptDelegate
245
- })
239
+ () => {
240
+ const policyOptions = {
241
+ trustFile: wpaths.projectTrust,
242
+ yolo: opts.permission?.yolo ?? false,
243
+ yoloDestructive: opts.permission?.yoloDestructive ?? opts.permission?.forceAllYolo ?? false,
244
+ confirmDestructive: opts.permission?.confirmDestructive ?? false
245
+ };
246
+ if (opts.permission?.promptDelegate !== void 0) {
247
+ policyOptions.promptDelegate = opts.permission.promptDelegate;
248
+ }
249
+ return new DefaultPermissionPolicy(policyOptions);
250
+ }
246
251
  );
247
252
  container.bind(
248
253
  TOKENS.Compactor,
@@ -1680,6 +1685,12 @@ async function saveProviders(configPath, vault, providers) {
1680
1685
  }
1681
1686
 
1682
1687
  // src/server/provider-keys.ts
1688
+ function expectDefined(value) {
1689
+ if (value === null || value === void 0) {
1690
+ throw new Error("Expected value to be defined");
1691
+ }
1692
+ return value;
1693
+ }
1683
1694
  function normalizeKeys(cfg) {
1684
1695
  if (Array.isArray(cfg.apiKeys) && cfg.apiKeys.length > 0) {
1685
1696
  return cfg.apiKeys.map((k) => ({ ...k }));
@@ -1697,7 +1708,7 @@ function writeKeysBack(cfg, keys) {
1697
1708
  return;
1698
1709
  }
1699
1710
  cfg.apiKeys = keys;
1700
- const active = keys.find((k) => k.label === cfg.activeKey) ?? keys[0];
1711
+ const active = keys.find((k) => k.label === cfg.activeKey) ?? expectDefined(keys[0]);
1701
1712
  cfg.apiKey = active.apiKey;
1702
1713
  if (!cfg.activeKey || !keys.some((k) => k.label === cfg.activeKey)) {
1703
1714
  cfg.activeKey = active.label;
@@ -1713,7 +1724,7 @@ function upsertKey(providers, providerId, label, apiKey, nowIso) {
1713
1724
  const keys = normalizeKeys(existing);
1714
1725
  const idx = keys.findIndex((k) => k.label === label);
1715
1726
  if (idx >= 0) {
1716
- keys[idx] = { ...keys[idx], apiKey, createdAt: nowIso };
1727
+ keys[idx] = { ...expectDefined(keys[idx]), apiKey, createdAt: nowIso };
1717
1728
  } else {
1718
1729
  keys.push({ label, apiKey, createdAt: nowIso });
1719
1730
  }
@@ -1732,7 +1743,7 @@ function deleteKey(providers, providerId, label) {
1732
1743
  delete providers[providerId];
1733
1744
  } else {
1734
1745
  writeKeysBack(existing, keys);
1735
- if (existing.activeKey === label) existing.activeKey = keys[0].label;
1746
+ if (existing.activeKey === label) existing.activeKey = keys[0]?.label;
1736
1747
  providers[providerId] = existing;
1737
1748
  }
1738
1749
  return { ok: true, message: `Key "${label}" deleted from ${providerId}` };
@@ -1985,6 +1996,12 @@ function estimateContextBreakdown(input) {
1985
1996
  }
1986
1997
 
1987
1998
  // src/server/index.ts
1999
+ function expectDefined2(value) {
2000
+ if (value === null || value === void 0) {
2001
+ throw new Error("Expected value to be defined");
2002
+ }
2003
+ return value;
2004
+ }
1988
2005
  async function startWebUI(opts = {}) {
1989
2006
  const requestedWsPort = opts.wsPort ?? 3457;
1990
2007
  const wsHost = opts.wsHost ?? "127.0.0.1";
@@ -2009,7 +2026,7 @@ async function startWebUI(opts = {}) {
2009
2026
  let configWriteLock = Promise.resolve();
2010
2027
  console.log("[WebUI] Config loaded:", config.provider ?? "(none)", "/", config.model ?? "(none)");
2011
2028
  if (!config.provider && config.providers && typeof config.providers === "object" && config.providers !== null && !Array.isArray(config.providers) && Object.keys(config.providers).length > 0) {
2012
- const firstKey = Object.keys(config.providers)[0];
2029
+ const firstKey = expectDefined2(Object.keys(config.providers)[0]);
2013
2030
  config = patchConfig(config, { provider: firstKey });
2014
2031
  console.log("[WebUI] No active provider \u2014 auto-selected:", firstKey);
2015
2032
  }
@@ -2042,6 +2059,9 @@ async function startWebUI(opts = {}) {
2042
2059
  const events = new EventBus();
2043
2060
  events.setLogger(logger);
2044
2061
  const sessionStore = new DefaultSessionStore2({ dir: wpaths.projectSessions });
2062
+ sessionStore.prune(30).then((count) => {
2063
+ if (count > 0) logger.info(`Pruned ${count} old session${count === 1 ? "" : "s"}.`);
2064
+ }).catch(() => void 0);
2045
2065
  const sessionReader = new DefaultSessionReader({ store: sessionStore });
2046
2066
  const annotationsStore = new AnnotationsStore({ dir: wpaths.projectSessions });
2047
2067
  let session = await sessionStore.create({
@@ -2105,7 +2125,7 @@ async function startWebUI(opts = {}) {
2105
2125
  const savedProviders = config.providers ?? {};
2106
2126
  const firstKey = Object.keys(savedProviders)[0];
2107
2127
  if (firstKey) {
2108
- const firstProvider = savedProviders[firstKey];
2128
+ const firstProvider = expectDefined2(savedProviders[firstKey]);
2109
2129
  try {
2110
2130
  provider = makeProviderFromConfig(firstKey, {
2111
2131
  ...firstProvider,
@@ -2933,7 +2953,7 @@ async function startWebUI(opts = {}) {
2933
2953
  sendResult(ws, false, "Todo not found");
2934
2954
  break;
2935
2955
  }
2936
- const removed = context.todos[targetIdx];
2956
+ const removed = expectDefined2(context.todos[targetIdx]);
2937
2957
  const next = [
2938
2958
  ...context.todos.slice(0, targetIdx),
2939
2959
  ...context.todos.slice(targetIdx + 1)