@tangle-network/agent-app 0.47.16 → 0.47.18

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ChatEmptyState,
3
3
  ChatMessages
4
- } from "../chunk-H6R3VYAZ.js";
4
+ } from "../chunk-WHHMYVDB.js";
5
5
  import "../chunk-F32T3DRJ.js";
6
6
  import "../chunk-3HUFJ5LO.js";
7
7
  import {
@@ -5016,6 +5016,39 @@ var defaultExpiryChoices = [1, 7, 30];
5016
5016
  var inputClass = "h-11 w-full rounded-lg border border-input bg-background px-3 text-sm text-foreground";
5017
5017
  var buttonClass = "inline-flex items-center justify-center rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50";
5018
5018
  var outlineClass = "inline-flex items-center justify-center rounded-lg border border-input bg-background px-3 py-2 text-sm font-medium text-foreground disabled:opacity-50";
5019
+ function pruneScopes(scopes, access) {
5020
+ const offered = new Map(access.map((option) => [option.scope, option]));
5021
+ const selected = new Set(scopes.filter((scope) => offered.has(scope)));
5022
+ let changed = true;
5023
+ while (changed) {
5024
+ changed = false;
5025
+ for (const scope of selected) {
5026
+ if (offered.get(scope)?.requires?.some((required) => !selected.has(required))) {
5027
+ selected.delete(scope);
5028
+ changed = true;
5029
+ }
5030
+ }
5031
+ }
5032
+ return [...selected];
5033
+ }
5034
+ function expandScopes(scopes, access) {
5035
+ const offered = new Map(access.map((option) => [option.scope, option]));
5036
+ const selected = /* @__PURE__ */ new Set();
5037
+ for (const scope of scopes) {
5038
+ const closure = /* @__PURE__ */ new Set([scope]);
5039
+ let available = true;
5040
+ for (const required of closure) {
5041
+ const option = offered.get(required);
5042
+ if (!option) {
5043
+ available = false;
5044
+ break;
5045
+ }
5046
+ for (const dependency of option.requires ?? []) closure.add(dependency);
5047
+ }
5048
+ if (available) for (const required of closure) selected.add(required);
5049
+ }
5050
+ return [...selected];
5051
+ }
5019
5052
  function ApiAccessPanel({
5020
5053
  keys,
5021
5054
  access,
@@ -5035,7 +5068,7 @@ function ApiAccessPanel({
5035
5068
  const fallbackDays = allowedDays.includes(defaultExpiryDays) ? defaultExpiryDays : allowedDays[0];
5036
5069
  const [days, setDays] = useState15(fallbackDays);
5037
5070
  const selectedDays = days !== void 0 && allowedDays.includes(days) ? days : fallbackDays;
5038
- const [scopes, setScopes] = useState15(() => defaultScopes.filter((scope) => access.some((option) => option.scope === scope)));
5071
+ const [scopes, setScopes] = useState15(() => expandScopes(defaultScopes, access));
5039
5072
  const [creating, setCreating] = useState15(false);
5040
5073
  const [revoking, setRevoking] = useState15(null);
5041
5074
  const [created, setCreated] = useState15(null);
@@ -5044,10 +5077,10 @@ function ApiAccessPanel({
5044
5077
  const keyHeading = useRef11(null);
5045
5078
  const nameInput = useRef11(null);
5046
5079
  const keyWasShown = useRef11(false);
5047
- const selectedScopes = scopes.filter((scope) => access.some((option) => option.scope === scope));
5080
+ const selectedScopes = pruneScopes(scopes, access);
5048
5081
  useEffect11(() => {
5049
5082
  setScopes((current) => {
5050
- const next = current.filter((scope) => access.some((option) => option.scope === scope));
5083
+ const next = pruneScopes(current, access);
5051
5084
  return next.length === current.length ? current : next;
5052
5085
  });
5053
5086
  }, [access]);
@@ -5062,7 +5095,7 @@ function ApiAccessPanel({
5062
5095
  }, [created]);
5063
5096
  async function createKey(event) {
5064
5097
  event.preventDefault();
5065
- const requestedScopes = scopes.filter((scope) => access.some((option) => option.scope === scope));
5098
+ const requestedScopes = pruneScopes(scopes, access);
5066
5099
  if (!name.trim() || !requestedScopes.length || selectedDays === void 0 || creating || created) return;
5067
5100
  setCreating(true);
5068
5101
  setError(null);
@@ -5140,21 +5173,26 @@ function ApiAccessPanel({
5140
5173
  ] }),
5141
5174
  /* @__PURE__ */ jsxs12("fieldset", { className: "space-y-3", children: [
5142
5175
  /* @__PURE__ */ jsx14("legend", { className: "mb-3 text-sm font-medium", children: "Permissions" }),
5143
- access.map((access2) => /* @__PURE__ */ jsxs12("label", { className: "flex cursor-pointer items-start gap-3", children: [
5144
- /* @__PURE__ */ jsx14(
5145
- "input",
5146
- {
5147
- type: "checkbox",
5148
- className: "mt-1 size-4 accent-primary",
5149
- checked: selectedScopes.includes(access2.scope),
5150
- onChange: (event) => setScopes((current) => event.target.checked ? [...current, access2.scope] : current.filter((scope) => scope !== access2.scope))
5151
- }
5152
- ),
5153
- /* @__PURE__ */ jsxs12("span", { className: "text-sm", children: [
5154
- /* @__PURE__ */ jsx14("span", { className: "block font-medium", children: access2.label }),
5155
- /* @__PURE__ */ jsx14("span", { className: "text-muted-foreground", children: access2.description })
5156
- ] })
5157
- ] }, access2.scope))
5176
+ access.map((option) => {
5177
+ const unavailable = !expandScopes([option.scope], access).includes(option.scope);
5178
+ return /* @__PURE__ */ jsxs12("label", { className: "flex cursor-pointer items-start gap-3", children: [
5179
+ /* @__PURE__ */ jsx14(
5180
+ "input",
5181
+ {
5182
+ type: "checkbox",
5183
+ className: "mt-1 size-4 accent-primary",
5184
+ checked: selectedScopes.includes(option.scope),
5185
+ disabled: unavailable,
5186
+ onChange: (event) => setScopes((current) => event.target.checked ? expandScopes([...current, option.scope], access) : pruneScopes(current.filter((scope) => scope !== option.scope), access))
5187
+ }
5188
+ ),
5189
+ /* @__PURE__ */ jsxs12("span", { className: "text-sm", children: [
5190
+ /* @__PURE__ */ jsx14("span", { className: "block font-medium", children: option.label }),
5191
+ /* @__PURE__ */ jsx14("span", { className: "text-muted-foreground", children: option.description }),
5192
+ unavailable && /* @__PURE__ */ jsx14("span", { className: "block text-muted-foreground", children: "Required permission unavailable." })
5193
+ ] })
5194
+ ] }, option.scope);
5195
+ })
5158
5196
  ] }),
5159
5197
  limitsDescription && /* @__PURE__ */ jsx14("p", { className: "text-xs text-muted-foreground", children: limitsDescription }),
5160
5198
  /* @__PURE__ */ jsx14("button", { className: buttonClass, type: "submit", disabled: creating || !name.trim() || !selectedScopes.length || selectedDays === void 0, children: creating ? "Creating\u2026" : "Create key" })
@@ -6129,4 +6167,4 @@ export {
6129
6167
  useThinkingSeconds,
6130
6168
  ChatMessages
6131
6169
  };
6132
- //# sourceMappingURL=chunk-H6R3VYAZ.js.map
6170
+ //# sourceMappingURL=chunk-WHHMYVDB.js.map