miladyai 2.0.0-alpha.27

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.
Files changed (241) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +7 -0
  2. package/dist/actions/emote.js +64 -0
  3. package/dist/actions/restart.js +81 -0
  4. package/dist/actions/send-message.js +152 -0
  5. package/dist/agent-admin-routes.js +82 -0
  6. package/dist/agent-lifecycle-routes.js +79 -0
  7. package/dist/agent-transfer-routes.js +102 -0
  8. package/dist/api/agent-admin-routes.js +82 -0
  9. package/dist/api/agent-lifecycle-routes.js +79 -0
  10. package/dist/api/agent-transfer-routes.js +102 -0
  11. package/dist/api/apps-hyperscape-routes.js +58 -0
  12. package/dist/api/apps-routes.js +114 -0
  13. package/dist/api/auth-routes.js +56 -0
  14. package/dist/api/autonomy-routes.js +44 -0
  15. package/dist/api/bug-report-routes.js +111 -0
  16. package/dist/api/character-routes.js +195 -0
  17. package/dist/api/cloud-routes.js +330 -0
  18. package/dist/api/cloud-status-routes.js +155 -0
  19. package/dist/api/compat-utils.js +111 -0
  20. package/dist/api/database.js +735 -0
  21. package/dist/api/diagnostics-routes.js +205 -0
  22. package/dist/api/drop-service.js +134 -0
  23. package/dist/api/early-logs.js +86 -0
  24. package/dist/api/http-helpers.js +131 -0
  25. package/dist/api/knowledge-routes.js +534 -0
  26. package/dist/api/memory-bounds.js +71 -0
  27. package/dist/api/models-routes.js +28 -0
  28. package/dist/api/og-tracker.js +36 -0
  29. package/dist/api/permissions-routes.js +109 -0
  30. package/dist/api/plugin-validation.js +198 -0
  31. package/dist/api/provider-switch-config.js +41 -0
  32. package/dist/api/registry-routes.js +86 -0
  33. package/dist/api/registry-service.js +164 -0
  34. package/dist/api/sandbox-routes.js +1112 -0
  35. package/dist/api/server.js +7949 -0
  36. package/dist/api/subscription-routes.js +172 -0
  37. package/dist/api/terminal-run-limits.js +24 -0
  38. package/dist/api/training-routes.js +158 -0
  39. package/dist/api/trajectory-routes.js +300 -0
  40. package/dist/api/trigger-routes.js +246 -0
  41. package/dist/api/twitter-verify.js +134 -0
  42. package/dist/api/tx-service.js +108 -0
  43. package/dist/api/wallet-routes.js +266 -0
  44. package/dist/api/wallet.js +568 -0
  45. package/dist/api/whatsapp-routes.js +182 -0
  46. package/dist/api/zip-utils.js +109 -0
  47. package/dist/apps-hyperscape-routes.js +58 -0
  48. package/dist/apps-routes.js +114 -0
  49. package/dist/ascii.js +20 -0
  50. package/dist/auth/anthropic.js +44 -0
  51. package/dist/auth/apply-stealth.js +41 -0
  52. package/dist/auth/claude-code-stealth.js +78 -0
  53. package/dist/auth/credentials.js +156 -0
  54. package/dist/auth/index.js +5 -0
  55. package/dist/auth/openai-codex.js +66 -0
  56. package/dist/auth/types.js +9 -0
  57. package/dist/auth-routes.js +56 -0
  58. package/dist/autonomy-routes.js +44 -0
  59. package/dist/bug-report-routes.js +111 -0
  60. package/dist/build-info.json +6 -0
  61. package/dist/character-routes.js +195 -0
  62. package/dist/cli/argv.js +63 -0
  63. package/dist/cli/banner.js +34 -0
  64. package/dist/cli/cli-name.js +21 -0
  65. package/dist/cli/cli-utils.js +16 -0
  66. package/dist/cli/git-commit.js +78 -0
  67. package/dist/cli/parse-duration.js +15 -0
  68. package/dist/cli/plugins-cli.js +590 -0
  69. package/dist/cli/profile-utils.js +9 -0
  70. package/dist/cli/profile.js +95 -0
  71. package/dist/cli/program/build-program.js +17 -0
  72. package/dist/cli/program/command-registry.js +23 -0
  73. package/dist/cli/program/help.js +47 -0
  74. package/dist/cli/program/preaction.js +33 -0
  75. package/dist/cli/program/register.config.js +106 -0
  76. package/dist/cli/program/register.configure.js +20 -0
  77. package/dist/cli/program/register.dashboard.js +124 -0
  78. package/dist/cli/program/register.models.js +23 -0
  79. package/dist/cli/program/register.setup.js +36 -0
  80. package/dist/cli/program/register.start.js +22 -0
  81. package/dist/cli/program/register.subclis.js +70 -0
  82. package/dist/cli/program/register.tui.js +163 -0
  83. package/dist/cli/program/register.update.js +154 -0
  84. package/dist/cli/program.js +3 -0
  85. package/dist/cli/run-main.js +37 -0
  86. package/dist/cli/version.js +7 -0
  87. package/dist/cloud/validate-url.js +93 -0
  88. package/dist/cloud-routes.js +330 -0
  89. package/dist/cloud-status-routes.js +155 -0
  90. package/dist/compat-utils.js +111 -0
  91. package/dist/config/config.js +69 -0
  92. package/dist/config/env-vars.js +19 -0
  93. package/dist/config/includes.js +121 -0
  94. package/dist/config/object-utils.js +7 -0
  95. package/dist/config/paths.js +38 -0
  96. package/dist/config/plugin-auto-enable.js +231 -0
  97. package/dist/config/schema.js +864 -0
  98. package/dist/config/telegram-custom-commands.js +76 -0
  99. package/dist/config/zod-schema.agent-runtime.js +519 -0
  100. package/dist/config/zod-schema.core.js +538 -0
  101. package/dist/config/zod-schema.hooks.js +103 -0
  102. package/dist/config/zod-schema.js +488 -0
  103. package/dist/config/zod-schema.providers-core.js +785 -0
  104. package/dist/config/zod-schema.session.js +73 -0
  105. package/dist/core-plugins.js +37 -0
  106. package/dist/custom-actions.js +250 -0
  107. package/dist/database.js +735 -0
  108. package/dist/diagnostics/integration-observability.js +57 -0
  109. package/dist/diagnostics-routes.js +205 -0
  110. package/dist/drop-service.js +134 -0
  111. package/dist/early-logs.js +24 -0
  112. package/dist/eliza.js +2061 -0
  113. package/dist/emotes/catalog.js +271 -0
  114. package/dist/entry.js +40 -0
  115. package/dist/hooks/discovery.js +167 -0
  116. package/dist/hooks/eligibility.js +64 -0
  117. package/dist/hooks/index.js +4 -0
  118. package/dist/hooks/loader.js +147 -0
  119. package/dist/hooks/registry.js +55 -0
  120. package/dist/http-helpers.js +131 -0
  121. package/dist/index.js +49 -0
  122. package/dist/knowledge-routes.js +534 -0
  123. package/dist/memory-bounds.js +71 -0
  124. package/dist/milady-plugin.js +90 -0
  125. package/dist/models-routes.js +28 -0
  126. package/dist/onboarding-names.js +78 -0
  127. package/dist/onboarding-presets.js +922 -0
  128. package/dist/package.json +1 -0
  129. package/dist/permissions-routes.js +109 -0
  130. package/dist/plugin-validation.js +107 -0
  131. package/dist/plugins/whatsapp/actions.js +91 -0
  132. package/dist/plugins/whatsapp/index.js +16 -0
  133. package/dist/plugins/whatsapp/service.js +270 -0
  134. package/dist/provider-switch-config.js +41 -0
  135. package/dist/providers/admin-trust.js +46 -0
  136. package/dist/providers/autonomous-state.js +101 -0
  137. package/dist/providers/session-bridge.js +86 -0
  138. package/dist/providers/session-utils.js +36 -0
  139. package/dist/providers/simple-mode.js +50 -0
  140. package/dist/providers/ui-catalog.js +15 -0
  141. package/dist/providers/workspace-provider.js +93 -0
  142. package/dist/providers/workspace.js +348 -0
  143. package/dist/registry-routes.js +86 -0
  144. package/dist/registry-service.js +164 -0
  145. package/dist/restart.js +40 -0
  146. package/dist/runtime/core-plugins.js +37 -0
  147. package/dist/runtime/custom-actions.js +250 -0
  148. package/dist/runtime/eliza.js +2061 -0
  149. package/dist/runtime/embedding-manager-support.js +185 -0
  150. package/dist/runtime/embedding-manager.js +193 -0
  151. package/dist/runtime/embedding-presets.js +54 -0
  152. package/dist/runtime/embedding-state.js +8 -0
  153. package/dist/runtime/milady-plugin.js +90 -0
  154. package/dist/runtime/onboarding-names.js +78 -0
  155. package/dist/runtime/restart.js +40 -0
  156. package/dist/runtime/version.js +7 -0
  157. package/dist/sandbox-routes.js +1112 -0
  158. package/dist/security/audit-log.js +149 -0
  159. package/dist/security/network-policy.js +70 -0
  160. package/dist/server.js +7949 -0
  161. package/dist/services/agent-export.js +559 -0
  162. package/dist/services/app-manager.js +389 -0
  163. package/dist/services/browser-capture.js +86 -0
  164. package/dist/services/fallback-training-service.js +128 -0
  165. package/dist/services/mcp-marketplace.js +134 -0
  166. package/dist/services/plugin-installer.js +396 -0
  167. package/dist/services/plugin-manager-types.js +15 -0
  168. package/dist/services/registry-client-app-meta.js +144 -0
  169. package/dist/services/registry-client-endpoints.js +166 -0
  170. package/dist/services/registry-client-local.js +271 -0
  171. package/dist/services/registry-client-network.js +93 -0
  172. package/dist/services/registry-client-queries.js +70 -0
  173. package/dist/services/registry-client.js +157 -0
  174. package/dist/services/sandbox-engine.js +511 -0
  175. package/dist/services/sandbox-manager.js +297 -0
  176. package/dist/services/self-updater.js +175 -0
  177. package/dist/services/skill-catalog-client.js +119 -0
  178. package/dist/services/skill-marketplace.js +521 -0
  179. package/dist/services/stream-manager.js +236 -0
  180. package/dist/services/update-checker.js +121 -0
  181. package/dist/services/update-notifier.js +29 -0
  182. package/dist/services/version-compat.js +78 -0
  183. package/dist/services/whatsapp-pairing.js +196 -0
  184. package/dist/shared/ui-catalog-prompt.js +728 -0
  185. package/dist/subscription-routes.js +172 -0
  186. package/dist/terminal/links.js +19 -0
  187. package/dist/terminal/palette.js +14 -0
  188. package/dist/terminal/theme.js +25 -0
  189. package/dist/terminal-run-limits.js +24 -0
  190. package/dist/training-routes.js +158 -0
  191. package/dist/trajectory-routes.js +300 -0
  192. package/dist/trigger-routes.js +246 -0
  193. package/dist/triggers/action.js +218 -0
  194. package/dist/triggers/runtime.js +281 -0
  195. package/dist/triggers/scheduling.js +295 -0
  196. package/dist/triggers/types.js +5 -0
  197. package/dist/tui/components/assistant-message.js +76 -0
  198. package/dist/tui/components/chat-editor.js +34 -0
  199. package/dist/tui/components/embeddings-overlay.js +46 -0
  200. package/dist/tui/components/footer.js +60 -0
  201. package/dist/tui/components/index.js +15 -0
  202. package/dist/tui/components/modal-frame.js +45 -0
  203. package/dist/tui/components/modal-style.js +15 -0
  204. package/dist/tui/components/model-selector.js +70 -0
  205. package/dist/tui/components/pinned-chat-layout.js +46 -0
  206. package/dist/tui/components/plugins-endpoints-tab.js +196 -0
  207. package/dist/tui/components/plugins-installed-tab-view.js +69 -0
  208. package/dist/tui/components/plugins-installed-tab.js +319 -0
  209. package/dist/tui/components/plugins-overlay-catalog.js +81 -0
  210. package/dist/tui/components/plugins-overlay-data-api.js +21 -0
  211. package/dist/tui/components/plugins-overlay-data-shared.js +20 -0
  212. package/dist/tui/components/plugins-overlay-data.js +323 -0
  213. package/dist/tui/components/plugins-overlay.js +117 -0
  214. package/dist/tui/components/plugins-store-tab.js +148 -0
  215. package/dist/tui/components/settings-overlay.js +61 -0
  216. package/dist/tui/components/status-bar.js +64 -0
  217. package/dist/tui/components/tool-execution.js +68 -0
  218. package/dist/tui/components/user-message.js +22 -0
  219. package/dist/tui/eliza-tui-bridge.js +606 -0
  220. package/dist/tui/index.js +370 -0
  221. package/dist/tui/modal-presets.js +33 -0
  222. package/dist/tui/model-spec.js +46 -0
  223. package/dist/tui/sse-parser.js +78 -0
  224. package/dist/tui/theme.js +110 -0
  225. package/dist/tui/titlebar-spinner.js +62 -0
  226. package/dist/tui/tui-app.js +311 -0
  227. package/dist/tui/ws-client.js +215 -0
  228. package/dist/twitter-verify.js +134 -0
  229. package/dist/tx-service.js +108 -0
  230. package/dist/utils/exec-safety.js +17 -0
  231. package/dist/utils/globals.js +20 -0
  232. package/dist/utils/milady-root.js +61 -0
  233. package/dist/utils/number-parsing.js +37 -0
  234. package/dist/version-resolver.js +37 -0
  235. package/dist/version.js +7 -0
  236. package/dist/wallet-routes.js +266 -0
  237. package/dist/wallet.js +568 -0
  238. package/dist/whatsapp-routes.js +182 -0
  239. package/dist/zip-utils.js +109 -0
  240. package/milady.mjs +14 -0
  241. package/package.json +111 -0
@@ -0,0 +1,46 @@
1
+ //#region src/tui/components/pinned-chat-layout.ts
2
+ /**
3
+ * Keeps the bottom UI chrome (status + editor + footer) pinned to the terminal
4
+ * bottom while showing the most recent chat lines above it.
5
+ */
6
+ var PinnedChatLayout = class {
7
+ constructor(options) {
8
+ this.options = options;
9
+ }
10
+ render(width) {
11
+ const rows = Math.max(1, this.options.getTerminalRows());
12
+ const chatLines = this.options.chat.render(width);
13
+ const ephemeralLines = this.options.ephemeralStatus.render(width);
14
+ const statusLines = this.options.statusBar.render(width);
15
+ const editorLines = this.options.editor.render(width);
16
+ const footerLines = this.options.footer.render(width);
17
+ const spacerCount = Math.max(0, this.options.spacerLines ?? 1);
18
+ const spacerLines = Array.from({ length: spacerCount }, () => "");
19
+ const bottomLines = [
20
+ ...ephemeralLines,
21
+ ...statusLines,
22
+ ...spacerLines,
23
+ ...editorLines,
24
+ ...footerLines
25
+ ];
26
+ if (bottomLines.length >= rows) return bottomLines.slice(bottomLines.length - rows);
27
+ const chatBudget = rows - bottomLines.length;
28
+ const visibleChat = chatLines.length > chatBudget ? chatLines.slice(chatLines.length - chatBudget) : chatLines;
29
+ const padding = Array.from({ length: Math.max(0, chatBudget - visibleChat.length) }, () => "");
30
+ return [
31
+ ...visibleChat,
32
+ ...padding,
33
+ ...bottomLines
34
+ ];
35
+ }
36
+ invalidate() {
37
+ this.options.chat.invalidate?.();
38
+ this.options.ephemeralStatus.invalidate?.();
39
+ this.options.statusBar.invalidate?.();
40
+ this.options.editor.invalidate?.();
41
+ this.options.footer.invalidate?.();
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ export { PinnedChatLayout };
@@ -0,0 +1,196 @@
1
+ import { tuiTheme } from "../theme.js";
2
+ import chalk from "chalk";
3
+ import { Input, SettingsList, getEditorKeybindings } from "@mariozechner/pi-tui";
4
+
5
+ //#region src/tui/components/plugins-endpoints-tab.ts
6
+ const endpointsListTheme = {
7
+ label: (text, selected) => selected ? tuiTheme.accent(text) : text,
8
+ value: (text, selected) => selected ? tuiTheme.accent(text) : tuiTheme.muted(text),
9
+ description: (text) => tuiTheme.dim(text),
10
+ cursor: tuiTheme.accent("→ "),
11
+ hint: (text) => tuiTheme.dim(text)
12
+ };
13
+ /**
14
+ * Endpoints tab — manage plugin registry endpoint URLs.
15
+ * Default endpoint is shown with [default] badge and cannot be removed.
16
+ */
17
+ var PluginEndpointsTab = class {
18
+ constructor(options) {
19
+ this.focused = false;
20
+ this.state = "list";
21
+ this.labelInput = new Input();
22
+ this.urlInput = new Input();
23
+ this.pendingLabel = "";
24
+ this.deleteUrl = "";
25
+ this.lastInteractedId = "";
26
+ this.endpointIds = [];
27
+ this.selectedIdx = 0;
28
+ this.options = options;
29
+ this.rebuildList();
30
+ }
31
+ /** Whether the tab is in an input-consuming state (add/delete flows). */
32
+ isCapturingInput() {
33
+ return this.state !== "list";
34
+ }
35
+ rebuildList() {
36
+ const endpoints = this.options.getEndpoints();
37
+ const items = [];
38
+ this.endpointIds = [];
39
+ items.push({
40
+ id: "__default__",
41
+ label: "ElizaOS Registry [default]",
42
+ currentValue: "always on",
43
+ values: ["always on"]
44
+ });
45
+ this.endpointIds.push("__default__");
46
+ for (const ep of endpoints) {
47
+ const enabled = ep.enabled !== false;
48
+ items.push({
49
+ id: ep.url,
50
+ label: `${ep.label}`,
51
+ description: ep.url,
52
+ currentValue: enabled ? "on" : "off",
53
+ values: ["on", "off"]
54
+ });
55
+ this.endpointIds.push(ep.url);
56
+ }
57
+ this.settingsList = new SettingsList(items, 12, endpointsListTheme, (id, newValue) => {
58
+ this.lastInteractedId = id;
59
+ if (id === "__default__") return;
60
+ this.options.toggleEndpoint(id, newValue === "on");
61
+ this.rebuildList();
62
+ this.options.requestRender();
63
+ }, () => this.options.onClose());
64
+ }
65
+ handleInput(data) {
66
+ const kb = getEditorKeybindings();
67
+ switch (this.state) {
68
+ case "list": {
69
+ const kb2 = getEditorKeybindings();
70
+ if (kb2.matches(data, "selectUp")) {
71
+ this.selectedIdx = Math.max(0, this.selectedIdx - 1);
72
+ this.lastInteractedId = this.endpointIds[this.selectedIdx] ?? "";
73
+ } else if (kb2.matches(data, "selectDown")) {
74
+ this.selectedIdx = Math.min(this.endpointIds.length - 1, this.selectedIdx + 1);
75
+ this.lastInteractedId = this.endpointIds[this.selectedIdx] ?? "";
76
+ }
77
+ if (data === "a") {
78
+ this.state = "add-label";
79
+ this.labelInput.setValue("");
80
+ this.options.requestRender();
81
+ return;
82
+ }
83
+ if (data === "d") {
84
+ if (this.lastInteractedId && this.lastInteractedId !== "__default__" && !this.options.isDefaultEndpoint(this.lastInteractedId)) {
85
+ this.deleteUrl = this.lastInteractedId;
86
+ this.state = "confirm-delete";
87
+ this.options.requestRender();
88
+ return;
89
+ }
90
+ return;
91
+ }
92
+ this.settingsList.handleInput(data);
93
+ break;
94
+ }
95
+ case "add-label":
96
+ if (kb.matches(data, "selectCancel")) {
97
+ this.state = "list";
98
+ this.options.requestRender();
99
+ return;
100
+ }
101
+ if (data === "\r" || data === "\n") {
102
+ const label = this.labelInput.getValue().trim();
103
+ if (label) {
104
+ this.pendingLabel = label;
105
+ this.state = "add-url";
106
+ this.urlInput.setValue("");
107
+ this.options.requestRender();
108
+ }
109
+ return;
110
+ }
111
+ this.labelInput.handleInput(data);
112
+ break;
113
+ case "add-url":
114
+ if (kb.matches(data, "selectCancel")) {
115
+ this.state = "list";
116
+ this.options.requestRender();
117
+ return;
118
+ }
119
+ if (data === "\r" || data === "\n") {
120
+ const url = this.urlInput.getValue().trim();
121
+ if (url) {
122
+ try {
123
+ this.options.addEndpoint(this.pendingLabel, url);
124
+ this.rebuildList();
125
+ } catch (_err) {}
126
+ this.state = "list";
127
+ this.options.requestRender();
128
+ }
129
+ return;
130
+ }
131
+ this.urlInput.handleInput(data);
132
+ break;
133
+ case "confirm-delete":
134
+ if (data === "y" || data === "Y") {
135
+ try {
136
+ this.options.removeEndpoint(this.deleteUrl);
137
+ this.rebuildList();
138
+ } catch {}
139
+ this.state = "list";
140
+ this.options.requestRender();
141
+ return;
142
+ }
143
+ if (data === "n" || data === "N" || kb.matches(data, "selectCancel")) {
144
+ this.state = "list";
145
+ this.options.requestRender();
146
+ return;
147
+ }
148
+ break;
149
+ }
150
+ }
151
+ render(width) {
152
+ switch (this.state) {
153
+ case "add-label":
154
+ this.labelInput.focused = this.focused;
155
+ return [
156
+ chalk.bold(" Add Registry Endpoint"),
157
+ "",
158
+ " Label:",
159
+ ...this.labelInput.render(width).map((l) => ` ${l}`),
160
+ "",
161
+ tuiTheme.dim(" Enter to continue • Esc to cancel")
162
+ ];
163
+ case "add-url":
164
+ this.urlInput.focused = this.focused;
165
+ return [
166
+ chalk.bold(" Add Registry Endpoint"),
167
+ "",
168
+ ` Label: ${tuiTheme.accent(this.pendingLabel)}`,
169
+ " URL:",
170
+ ...this.urlInput.render(width).map((l) => ` ${l}`),
171
+ "",
172
+ tuiTheme.dim(" Enter to save • Esc to cancel")
173
+ ];
174
+ case "confirm-delete": return [
175
+ "",
176
+ ` ${tuiTheme.warning("Delete endpoint?")}`,
177
+ ` ${tuiTheme.dim(this.deleteUrl)}`,
178
+ "",
179
+ ` ${tuiTheme.accent("y")} to confirm • ${tuiTheme.accent("n")} to cancel`
180
+ ];
181
+ default: return [
182
+ ...this.settingsList.render(width),
183
+ "",
184
+ tuiTheme.dim(" ↑↓ navigate • Enter/Space toggle • a add • d delete • Esc close")
185
+ ];
186
+ }
187
+ }
188
+ invalidate() {
189
+ this.settingsList.invalidate();
190
+ this.labelInput.invalidate();
191
+ this.urlInput.invalidate();
192
+ }
193
+ };
194
+
195
+ //#endregion
196
+ export { PluginEndpointsTab };
@@ -0,0 +1,69 @@
1
+ import { tuiTheme } from "../theme.js";
2
+
3
+ //#region src/tui/components/plugins-installed-tab-view.ts
4
+ function formatSettingValue(value, showUnmaskedValues) {
5
+ if (value === "") return tuiTheme.dim("(empty)");
6
+ if (showUnmaskedValues) return value;
7
+ return tuiTheme.muted("•".repeat(Math.max(8, Math.min(24, value.length))));
8
+ }
9
+ function renderEditSelectView(params) {
10
+ const { editingPluginName, editingKeys, editingIndex, editingDraft, editingParamsByKey, showUnmaskedValues } = params;
11
+ const lines = [];
12
+ lines.push(` ${tuiTheme.accent("Edit Plugin Settings")}`);
13
+ lines.push(` ${tuiTheme.dim(editingPluginName)}`);
14
+ lines.push("");
15
+ if (editingKeys.length === 0) {
16
+ lines.push(tuiTheme.dim(" No settings yet. Press 'a' to add one."));
17
+ lines.push("");
18
+ lines.push(tuiTheme.dim(" a add setting • s save • Esc cancel"));
19
+ return lines;
20
+ }
21
+ const labels = editingKeys.map((key) => {
22
+ const param = editingParamsByKey[key];
23
+ const requiredBadge = param?.required ? " *" : "";
24
+ return `${param?.label ?? key}${requiredBadge}`;
25
+ });
26
+ const maxLabelWidth = Math.max(...labels.map((label) => label.length));
27
+ editingKeys.forEach((key, idx) => {
28
+ const selected = idx === editingIndex;
29
+ const value = editingDraft[key] ?? "";
30
+ const cursor = selected ? tuiTheme.accent("→") : " ";
31
+ const label = (labels[idx] ?? key).padEnd(maxLabelWidth);
32
+ const renderedValue = formatSettingValue(value, showUnmaskedValues);
33
+ const line = `${cursor} ${selected ? tuiTheme.accent(label) : label} ${renderedValue}`;
34
+ lines.push(` ${line}`);
35
+ });
36
+ lines.push("");
37
+ lines.push(tuiTheme.dim(" * required"));
38
+ lines.push(tuiTheme.dim(` ↑↓ select setting • Enter edit value • a add • s save • Ctrl+U ${showUnmaskedValues ? "mask" : "unmask"} • Esc cancel`));
39
+ return lines;
40
+ }
41
+ function renderAddKeyView(params) {
42
+ const { width, focused, editingPluginName, newKeyInput } = params;
43
+ newKeyInput.focused = focused;
44
+ return [
45
+ ` ${tuiTheme.accent("Add Setting Key")}`,
46
+ ` ${tuiTheme.dim(editingPluginName)}`,
47
+ "",
48
+ ...newKeyInput.render(width).map((line) => ` ${line}`),
49
+ "",
50
+ tuiTheme.dim(" Enter continue • Esc back")
51
+ ];
52
+ }
53
+ function renderEditValueView(params) {
54
+ const { width, focused, editingPluginName, editingKeys, editingIndex, showUnmaskedValues, valueInput } = params;
55
+ const key = editingKeys[editingIndex] ?? "";
56
+ valueInput.focused = focused;
57
+ const valueLines = showUnmaskedValues ? valueInput.render(width).map((line) => ` ${line}`) : [` ${tuiTheme.accent("→")} ${tuiTheme.muted("•".repeat(valueInput.getValue().length))}`];
58
+ return [
59
+ ` ${tuiTheme.accent("Edit Value")}`,
60
+ ` ${tuiTheme.dim(`${editingPluginName} • ${key}`)}`,
61
+ "",
62
+ ...valueLines,
63
+ "",
64
+ tuiTheme.dim(` Enter apply • Ctrl+U ${showUnmaskedValues ? "mask" : "unmask"} • Esc back`)
65
+ ];
66
+ }
67
+
68
+ //#endregion
69
+ export { renderAddKeyView, renderEditSelectView, renderEditValueView };
@@ -0,0 +1,319 @@
1
+ import { tuiTheme } from "../theme.js";
2
+ import { renderAddKeyView, renderEditSelectView, renderEditValueView } from "./plugins-installed-tab-view.js";
3
+ import { Input, SelectList, getEditorKeybindings, matchesKey } from "@mariozechner/pi-tui";
4
+
5
+ //#region src/tui/components/plugins-installed-tab.ts
6
+ /**
7
+ * Installed Plugins tab — filterable list of installed/loaded plugins with
8
+ * enable/disable toggle and per-plugin configuration.
9
+ */
10
+ var InstalledPluginsTab = class {
11
+ constructor(options) {
12
+ this.focused = false;
13
+ this.filterInput = new Input();
14
+ this.pluginsById = /* @__PURE__ */ new Map();
15
+ this.allItems = [];
16
+ this.loading = true;
17
+ this.state = "list";
18
+ this.editingPluginId = null;
19
+ this.editingPluginName = "";
20
+ this.editingKeys = [];
21
+ this.editingParamsByKey = {};
22
+ this.editingDraft = {};
23
+ this.editingIndex = 0;
24
+ this.valueInput = new Input();
25
+ this.newKeyInput = new Input();
26
+ this.showUnmaskedValues = false;
27
+ this.statusMessage = "";
28
+ this.options = options;
29
+ this.selectList = new SelectList([], 14, tuiTheme.selectList);
30
+ this.selectList.onCancel = () => options.onClose();
31
+ this.filterInput.setValue("");
32
+ this.loadPlugins();
33
+ }
34
+ /** Whether the tab is in an input-consuming state. */
35
+ isCapturingInput() {
36
+ return this.state !== "list";
37
+ }
38
+ async loadPlugins() {
39
+ this.loading = true;
40
+ this.options.requestRender();
41
+ try {
42
+ const plugins = await this.options.getPlugins();
43
+ plugins.sort((a, b) => {
44
+ if (a.enabled !== b.enabled) return a.enabled ? -1 : 1;
45
+ return a.name.localeCompare(b.name);
46
+ });
47
+ this.pluginsById.clear();
48
+ this.allItems = [];
49
+ for (const p of plugins) {
50
+ this.pluginsById.set(p.id, p);
51
+ const statusBadge = p.enabled ? tuiTheme.success("[ON]") : tuiTheme.dim("[OFF]");
52
+ const configHint = p.configStatus.total === 0 ? tuiTheme.dim("(no config)") : `(${p.configStatus.set}/${p.configStatus.total} configured)`;
53
+ this.allItems.push({
54
+ value: p.id,
55
+ label: `${p.name} ${statusBadge}`,
56
+ description: `${p.category} v${p.version} ${configHint}`
57
+ });
58
+ }
59
+ this.selectList = new SelectList(this.allItems, 14, tuiTheme.selectList);
60
+ this.selectList.onCancel = () => this.options.onClose();
61
+ this.selectList.onSelect = (item) => {
62
+ this.handlePluginSelect(item.value);
63
+ };
64
+ const filter = this.filterInput.getValue();
65
+ if (filter) this.selectList.setFilter(filter);
66
+ } catch {} finally {
67
+ this.loading = false;
68
+ this.options.requestRender();
69
+ }
70
+ }
71
+ async handlePluginSelect(pluginId) {
72
+ const plugin = this.pluginsById.get(pluginId);
73
+ if (!plugin) return;
74
+ const newEnabled = !plugin.enabled;
75
+ await this.options.onTogglePlugin(pluginId, newEnabled);
76
+ this.statusMessage = `${plugin.name} ${newEnabled ? "enabled" : "disabled"}.`;
77
+ this.loadPlugins();
78
+ }
79
+ beginEditSelectedPlugin() {
80
+ const selected = this.selectList.getSelectedItem();
81
+ if (!selected) return;
82
+ const plugin = this.pluginsById.get(selected.value);
83
+ if (!plugin) return;
84
+ this.editingPluginId = plugin.id;
85
+ this.editingPluginName = plugin.name;
86
+ this.editingParamsByKey = Object.fromEntries(plugin.parameters.map((p) => [p.key, p]));
87
+ this.editingKeys = [...plugin.parameters].sort((a, b) => {
88
+ const reqA = a.required ? 0 : 1;
89
+ const reqB = b.required ? 0 : 1;
90
+ if (reqA !== reqB) return reqA - reqB;
91
+ return a.key.localeCompare(b.key);
92
+ }).map((p) => p.key);
93
+ this.editingDraft = Object.fromEntries(plugin.parameters.map((p) => [p.key, p.value]));
94
+ this.editingIndex = 0;
95
+ this.showUnmaskedValues = false;
96
+ this.state = "edit-select";
97
+ this.statusMessage = "";
98
+ this.options.requestRender();
99
+ }
100
+ async saveEditingConfig() {
101
+ const pluginId = this.editingPluginId;
102
+ if (!pluginId) return;
103
+ const missingRequired = this.editingKeys.filter((key) => {
104
+ if (!this.editingParamsByKey[key]?.required) return false;
105
+ return (this.editingDraft[key] ?? "").trim() === "";
106
+ });
107
+ if (missingRequired.length > 0) {
108
+ this.statusMessage = tuiTheme.error(`Missing required settings: ${missingRequired.join(", ")}`);
109
+ this.options.requestRender();
110
+ return;
111
+ }
112
+ try {
113
+ await this.options.onConfigSave(pluginId, this.editingDraft);
114
+ this.statusMessage = `Saved settings for ${this.editingPluginName}.`;
115
+ this.state = "list";
116
+ this.editingPluginId = null;
117
+ this.editingPluginName = "";
118
+ this.editingKeys = [];
119
+ this.editingParamsByKey = {};
120
+ this.editingDraft = {};
121
+ this.editingIndex = 0;
122
+ await this.loadPlugins();
123
+ } catch (err) {
124
+ this.statusMessage = tuiTheme.error(`Failed to save: ${err instanceof Error ? err.message : String(err)}`);
125
+ this.options.requestRender();
126
+ }
127
+ }
128
+ cancelEditing() {
129
+ this.state = "list";
130
+ this.editingPluginId = null;
131
+ this.editingPluginName = "";
132
+ this.editingKeys = [];
133
+ this.editingParamsByKey = {};
134
+ this.editingDraft = {};
135
+ this.editingIndex = 0;
136
+ this.statusMessage = "Edit cancelled.";
137
+ this.options.requestRender();
138
+ }
139
+ toggleValueMask() {
140
+ this.showUnmaskedValues = !this.showUnmaskedValues;
141
+ this.options.requestRender();
142
+ }
143
+ handleEditSelectInput(data) {
144
+ const kb = getEditorKeybindings();
145
+ if (kb.matches(data, "selectCancel")) {
146
+ this.cancelEditing();
147
+ return;
148
+ }
149
+ if (matchesKey(data, "ctrl+u")) {
150
+ this.toggleValueMask();
151
+ return;
152
+ }
153
+ if (data === "a" || data === "A") {
154
+ this.newKeyInput.setValue("");
155
+ this.state = "add-key";
156
+ this.options.requestRender();
157
+ return;
158
+ }
159
+ if (kb.matches(data, "selectUp")) {
160
+ this.editingIndex = Math.max(0, this.editingIndex - 1);
161
+ this.options.requestRender();
162
+ return;
163
+ }
164
+ if (kb.matches(data, "selectDown")) {
165
+ this.editingIndex = Math.min(this.editingKeys.length - 1, this.editingIndex + 1);
166
+ this.options.requestRender();
167
+ return;
168
+ }
169
+ if (data === "s" || data === "S") {
170
+ this.saveEditingConfig();
171
+ return;
172
+ }
173
+ if (kb.matches(data, "selectConfirm") && this.editingKeys.length > 0) {
174
+ const key = this.editingKeys[this.editingIndex];
175
+ const currentValue = this.editingDraft[key] ?? "";
176
+ this.valueInput.setValue(currentValue);
177
+ this.state = "edit-value";
178
+ this.options.requestRender();
179
+ }
180
+ }
181
+ handleAddKeyInput(data) {
182
+ const kb = getEditorKeybindings();
183
+ if (kb.matches(data, "selectCancel")) {
184
+ this.state = "edit-select";
185
+ this.options.requestRender();
186
+ return;
187
+ }
188
+ if (kb.matches(data, "selectConfirm")) {
189
+ const key = this.newKeyInput.getValue().trim();
190
+ if (!key) {
191
+ this.statusMessage = tuiTheme.error("Setting key cannot be empty.");
192
+ this.options.requestRender();
193
+ return;
194
+ }
195
+ if (key in this.editingDraft) {
196
+ this.statusMessage = tuiTheme.error(`Setting "${key}" already exists.`);
197
+ this.options.requestRender();
198
+ return;
199
+ }
200
+ this.editingKeys.push(key);
201
+ this.editingParamsByKey[key] = {
202
+ key,
203
+ label: key,
204
+ value: "",
205
+ required: false
206
+ };
207
+ this.editingDraft[key] = "";
208
+ this.editingIndex = this.editingKeys.length - 1;
209
+ this.valueInput.setValue("");
210
+ this.state = "edit-value";
211
+ this.statusMessage = "";
212
+ this.options.requestRender();
213
+ return;
214
+ }
215
+ this.newKeyInput.handleInput(data);
216
+ this.options.requestRender();
217
+ }
218
+ handleEditValueInput(data) {
219
+ const kb = getEditorKeybindings();
220
+ if (kb.matches(data, "selectCancel")) {
221
+ this.state = "edit-select";
222
+ this.options.requestRender();
223
+ return;
224
+ }
225
+ if (matchesKey(data, "ctrl+u")) {
226
+ this.toggleValueMask();
227
+ return;
228
+ }
229
+ if (kb.matches(data, "selectConfirm")) {
230
+ const key = this.editingKeys[this.editingIndex];
231
+ this.editingDraft[key] = this.valueInput.getValue();
232
+ this.state = "edit-select";
233
+ this.options.requestRender();
234
+ return;
235
+ }
236
+ this.valueInput.handleInput(data);
237
+ this.options.requestRender();
238
+ }
239
+ handleInput(data) {
240
+ const kb = getEditorKeybindings();
241
+ if (this.state === "edit-select") {
242
+ this.handleEditSelectInput(data);
243
+ return;
244
+ }
245
+ if (this.state === "add-key") {
246
+ this.handleAddKeyInput(data);
247
+ return;
248
+ }
249
+ if (this.state === "edit-value") {
250
+ this.handleEditValueInput(data);
251
+ return;
252
+ }
253
+ if (kb.matches(data, "selectUp") || kb.matches(data, "selectDown") || kb.matches(data, "selectConfirm") || kb.matches(data, "selectCancel")) {
254
+ this.selectList.handleInput(data);
255
+ return;
256
+ }
257
+ if (data === " ") {
258
+ const selected = this.selectList.getSelectedItem();
259
+ if (selected) this.handlePluginSelect(selected.value);
260
+ return;
261
+ }
262
+ if (data === "e" || data === "E") {
263
+ this.beginEditSelectedPlugin();
264
+ return;
265
+ }
266
+ const before = this.filterInput.getValue();
267
+ this.filterInput.handleInput(data);
268
+ const after = this.filterInput.getValue();
269
+ if (after !== before) this.selectList.setFilter(after);
270
+ }
271
+ render(width) {
272
+ this.filterInput.focused = this.focused && this.state === "list";
273
+ if (this.loading && this.state === "list") return [tuiTheme.dim(" Loading installed plugins…")];
274
+ if (this.state === "edit-select") return renderEditSelectView({
275
+ editingPluginName: this.editingPluginName,
276
+ editingKeys: this.editingKeys,
277
+ editingIndex: this.editingIndex,
278
+ editingDraft: this.editingDraft,
279
+ editingParamsByKey: this.editingParamsByKey,
280
+ showUnmaskedValues: this.showUnmaskedValues
281
+ });
282
+ if (this.state === "add-key") return renderAddKeyView({
283
+ width,
284
+ focused: this.focused,
285
+ editingPluginName: this.editingPluginName,
286
+ newKeyInput: this.newKeyInput
287
+ });
288
+ if (this.state === "edit-value") return renderEditValueView({
289
+ width,
290
+ focused: this.focused,
291
+ editingPluginName: this.editingPluginName,
292
+ editingKeys: this.editingKeys,
293
+ editingIndex: this.editingIndex,
294
+ showUnmaskedValues: this.showUnmaskedValues,
295
+ valueInput: this.valueInput
296
+ });
297
+ const lines = [...this.filterInput.render(width).map((l) => ` ${l}`), ""];
298
+ if (this.statusMessage) {
299
+ lines.push(` ${this.statusMessage}`);
300
+ lines.push("");
301
+ }
302
+ if (this.allItems.length === 0) {
303
+ lines.push(tuiTheme.dim(" No plugins installed."));
304
+ lines.push(tuiTheme.dim(" Use the Store tab to browse and install plugins."));
305
+ } else lines.push(...this.selectList.render(width));
306
+ lines.push("");
307
+ lines.push(tuiTheme.dim(" ↑↓ navigate • Enter toggle • Space toggle • e edit settings • type to filter"));
308
+ return lines;
309
+ }
310
+ invalidate() {
311
+ this.filterInput.invalidate();
312
+ this.selectList.invalidate();
313
+ this.valueInput.invalidate();
314
+ this.newKeyInput.invalidate();
315
+ }
316
+ };
317
+
318
+ //#endregion
319
+ export { InstalledPluginsTab };