@linxin666/dsh-remote-web-ui 0.3.0 → 0.3.2

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/index.js CHANGED
@@ -2025,6 +2025,7 @@ function fieldsOf(model, includeId) {
2025
2025
  return fields;
2026
2026
  }
2027
2027
  function groupFor(catalog, provider) {
2028
+ if (catalog.failures.some((failure) => failure.id === provider)) return void 0;
2028
2029
  return catalog.groups.find((group) => group.id === provider);
2029
2030
  }
2030
2031
  async function readCatalog(apiProxy) {
@@ -2077,11 +2078,45 @@ async function eligibleProvider(apiProxy, requested) {
2077
2078
  profile
2078
2079
  } };
2079
2080
  }
2081
+ function validIdentifier(value) {
2082
+ const parsed = stringField(MAX_IDENTIFIER_LENGTH).safeParse(value);
2083
+ return parsed.success && parsed.data === value;
2084
+ }
2085
+ function configuredModels(profile) {
2086
+ if (!Object.hasOwn(profile, "models")) return { inherited: true };
2087
+ if (!Array.isArray(profile.models)) return void 0;
2088
+ if (profile.models.length === 0) return { inherited: true };
2089
+ const values = [];
2090
+ for (const entry of profile.models) {
2091
+ if (!isRecord(entry) || !validIdentifier(entry.id)) return void 0;
2092
+ values.push({ ...entry });
2093
+ }
2094
+ return {
2095
+ inherited: false,
2096
+ values
2097
+ };
2098
+ }
2099
+ function configuredOverrides(profile) {
2100
+ if (!Object.hasOwn(profile, "modelOverrides")) return {
2101
+ present: false,
2102
+ values: /* @__PURE__ */ new Map()
2103
+ };
2104
+ if (!isRecord(profile.modelOverrides)) return void 0;
2105
+ const values = /* @__PURE__ */ new Map();
2106
+ for (const [id, value] of Object.entries(profile.modelOverrides)) {
2107
+ if (!validIdentifier(id) || !isRecord(value)) return void 0;
2108
+ values.set(id, { ...value });
2109
+ }
2110
+ return {
2111
+ present: true,
2112
+ values
2113
+ };
2114
+ }
2080
2115
  function updatedModels(existing, model) {
2081
- const next = existing.map((entry) => isRecord(entry) ? { ...entry } : entry);
2082
- const index = next.findIndex((entry) => isRecord(entry) && entry.id === model.id);
2116
+ const next = existing.map((entry) => ({ ...entry }));
2117
+ const index = next.findIndex((entry) => entry.id === model.id);
2083
2118
  const patch = fieldsOf(model, true);
2084
- if (index >= 0 && isRecord(next[index])) next[index] = {
2119
+ if (index >= 0) next[index] = {
2085
2120
  ...next[index],
2086
2121
  ...patch
2087
2122
  };
@@ -2089,40 +2124,68 @@ function updatedModels(existing, model) {
2089
2124
  return next;
2090
2125
  }
2091
2126
  function mutationPlan(profile, provider, model, catalog) {
2092
- if (Array.isArray(profile.models)) return {
2093
- path: [
2094
- "providers",
2095
- provider,
2096
- "models"
2097
- ],
2098
- value: updatedModels(profile.models, model)
2099
- };
2127
+ const configured = configuredModels(profile);
2128
+ const overrides = configuredOverrides(profile);
2129
+ if (configured === void 0 || overrides === void 0) return void 0;
2130
+ const modelsPath = [
2131
+ "providers",
2132
+ provider,
2133
+ "models"
2134
+ ];
2135
+ const overridesPath = [
2136
+ "providers",
2137
+ provider,
2138
+ "modelOverrides"
2139
+ ];
2140
+ if (!configured.inherited) {
2141
+ if (overrides.values.size > 0) return void 0;
2142
+ const ops = [{
2143
+ op: "set",
2144
+ path: modelsPath,
2145
+ value: updatedModels(configured.values, model)
2146
+ }];
2147
+ if (overrides.present) ops.push({
2148
+ op: "unset",
2149
+ path: overridesPath
2150
+ });
2151
+ return { ops };
2152
+ }
2100
2153
  const group = groupFor(catalog, provider);
2101
2154
  if (group?.models.some((entry) => entry.id === model.id) === true) {
2102
- const current = (isRecord(profile.modelOverrides) ? profile.modelOverrides : void 0)?.[model.id];
2103
- const existing = isRecord(current) ? current : {};
2104
- return {
2105
- path: [
2106
- "providers",
2107
- provider,
2108
- "modelOverrides",
2109
- model.id
2110
- ],
2155
+ const existing = overrides.values.get(model.id) ?? {};
2156
+ return { ops: [{
2157
+ op: "set",
2158
+ path: [...overridesPath, model.id],
2111
2159
  value: {
2112
2160
  ...existing,
2113
2161
  ...fieldsOf(model, false)
2114
2162
  }
2115
- };
2163
+ }] };
2164
+ }
2165
+ if (group === void 0) return void 0;
2166
+ const materialized = [];
2167
+ const materializedIds = /* @__PURE__ */ new Set();
2168
+ for (const installed of group.models) {
2169
+ materialized.push({
2170
+ ...overrides.values.get(installed.id),
2171
+ id: installed.id
2172
+ });
2173
+ materializedIds.add(installed.id);
2116
2174
  }
2117
- if (group === void 0 || catalog.failures.some((failure) => failure.id === provider)) return void 0;
2118
- return {
2119
- path: [
2120
- "providers",
2121
- provider,
2122
- "models"
2123
- ],
2124
- value: [...group.models.map((entry) => ({ id: entry.id })), fieldsOf(model, true)]
2125
- };
2175
+ for (const [id, override] of overrides.values) if (!materializedIds.has(id)) materialized.push({
2176
+ ...override,
2177
+ id
2178
+ });
2179
+ const ops = [{
2180
+ op: "set",
2181
+ path: modelsPath,
2182
+ value: updatedModels(materialized, model)
2183
+ }];
2184
+ if (overrides.present) ops.push({
2185
+ op: "unset",
2186
+ path: overridesPath
2187
+ });
2188
+ return { ops };
2126
2189
  }
2127
2190
  function paired(req, service) {
2128
2191
  const deviceId = readCookie(req.headers.cookie, service.config.cookieName);
@@ -2214,11 +2277,7 @@ function makePairedModelCatalogRoutes(deps) {
2214
2277
  mutation = await apiProxy.settings.mutate(request$1({
2215
2278
  ns: "llm-pi-ai",
2216
2279
  expectedRevision: eligible.provider.namespace.revision,
2217
- ops: [{
2218
- op: "set",
2219
- path: plan.path,
2220
- value: plan.value
2221
- }]
2280
+ ops: plan.ops
2222
2281
  }));
2223
2282
  } catch {
2224
2283
  return reject(res, 502, `model update failed for provider ${body.provider}`);
package/lib/mobile.js CHANGED
@@ -15627,9 +15627,9 @@ function DirectoryBrowser({ onCancel, onPick }) {
15627
15627
  type: "button",
15628
15628
  className: `mobile-row dir-entry ${entry.hidden ? "dir-entry-hidden" : ""}`,
15629
15629
  onClick: () => setPath(entry.path),
15630
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
15630
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
15631
15631
  className: "mobile-rowTitle",
15632
- children: ["📁 ", entry.name]
15632
+ children: entry.name
15633
15633
  })
15634
15634
  }) }, entry.path))
15635
15635
  }),