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,250 @@
1
+ import { loadMiladyConfig } from "../config/config.js";
2
+ import { isBlockedPrivateOrLinkLocalIp, normalizeHostLike } from "../security/network-policy.js";
3
+ import { lookup } from "node:dns/promises";
4
+ import net from "node:net";
5
+
6
+ //#region src/runtime/custom-actions.ts
7
+ /**
8
+ * Custom Actions runtime loader.
9
+ *
10
+ * Converts `CustomActionDef[]` from config into ElizaOS `Action[]` objects
11
+ * so the agent can use them in conversations.
12
+ *
13
+ * @module runtime/custom-actions
14
+ */
15
+ /** Cached runtime reference for hot-registration of new actions. */
16
+ let _runtime = null;
17
+ /**
18
+ * Store the runtime reference so we can hot-register actions later.
19
+ * Called once from plugin.init().
20
+ */
21
+ function setCustomActionsRuntime(runtime) {
22
+ _runtime = runtime;
23
+ }
24
+ /**
25
+ * Hot-register a CustomActionDef into the running agent.
26
+ * Returns the ElizaOS Action that was registered, or null if no runtime.
27
+ */
28
+ function registerCustomActionLive(def) {
29
+ if (!_runtime) return null;
30
+ const action = defToAction(def);
31
+ _runtime.registerAction(action);
32
+ return action;
33
+ }
34
+ /** API port for shell handler requests. */
35
+ const API_PORT = process.env.API_PORT || process.env.SERVER_PORT || "2138";
36
+ /** Valid handler types that we actually support. */
37
+ const VALID_HANDLER_TYPES = new Set([
38
+ "http",
39
+ "shell",
40
+ "code"
41
+ ]);
42
+ let vmRunner = null;
43
+ function resolveFetchInputUrl(input) {
44
+ if (typeof input === "string") return input;
45
+ if (input instanceof URL) return input.toString();
46
+ if (typeof Request !== "undefined" && input instanceof Request) return input.url;
47
+ return null;
48
+ }
49
+ async function safeCodeFetch(input, init) {
50
+ const url = resolveFetchInputUrl(input);
51
+ if (!url || await isBlockedUrl(url)) throw new Error("Blocked: cannot make requests to internal network addresses");
52
+ const response = await fetch(input, {
53
+ ...init,
54
+ redirect: "manual"
55
+ });
56
+ if (response.status >= 300 && response.status < 400) throw new Error("Blocked: redirects are not allowed for code custom actions");
57
+ return response;
58
+ }
59
+ async function runCodeHandler(code, params) {
60
+ if (typeof process === "undefined" || !process.versions?.node) throw new Error("Code actions are only supported in Node runtimes.");
61
+ if (!vmRunner) vmRunner = await import("node:vm");
62
+ const script = `(async () => { ${code} })();`;
63
+ const context = {
64
+ params,
65
+ fetch: safeCodeFetch
66
+ };
67
+ return await vmRunner.runInNewContext(`"use strict"; ${script}`, context, {
68
+ filename: "milady-custom-action",
69
+ timeout: 3e4
70
+ });
71
+ }
72
+ /**
73
+ * Shell-escape a value so it can be safely interpolated into a shell command.
74
+ * Wraps in single quotes and escapes any embedded single quotes.
75
+ */
76
+ function shellEscape(value) {
77
+ return `'${value.replace(/'/g, "'\\''")}'`;
78
+ }
79
+ function isBlockedIp(ip) {
80
+ return isBlockedPrivateOrLinkLocalIp(ip);
81
+ }
82
+ /**
83
+ * Check whether a URL targets a private/internal network (SSRF guard).
84
+ * Blocks loopback, link-local, and RFC-1918 ranges except our own API.
85
+ * Resolves hostnames to concrete IPs to prevent DNS-alias bypasses.
86
+ */
87
+ async function isBlockedUrl(url) {
88
+ try {
89
+ const parsed = new URL(url);
90
+ const hostname = normalizeHostLike(parsed.hostname);
91
+ if ((hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1") && parsed.port === String(API_PORT)) return false;
92
+ if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "0.0.0.0" || hostname.endsWith(".local") || hostname === "[::1]" || hostname === "metadata.google.internal" || hostname === "169.254.169.254") return true;
93
+ if (net.isIP(hostname)) return isBlockedIp(hostname);
94
+ const records = await lookup(hostname, { all: true });
95
+ const addresses = Array.isArray(records) ? records : [records];
96
+ for (const entry of addresses) if (isBlockedIp(entry.address)) return true;
97
+ return false;
98
+ } catch {
99
+ return true;
100
+ }
101
+ }
102
+ /**
103
+ * Build an async handler function from a CustomActionHandler definition.
104
+ */
105
+ function buildHandler(handler, paramDefs) {
106
+ if (!VALID_HANDLER_TYPES.has(handler.type)) return async () => ({
107
+ ok: false,
108
+ output: `Unsupported handler type: ${handler.type}`
109
+ });
110
+ switch (handler.type) {
111
+ case "http": return async (params) => {
112
+ let url = handler.url;
113
+ let body = handler.bodyTemplate ?? "";
114
+ const headers = { ...handler.headers };
115
+ for (const p of paramDefs) {
116
+ const value = params[p.name] ?? "";
117
+ url = url.replaceAll(`{{${p.name}}}`, encodeURIComponent(value));
118
+ body = body.replaceAll(`{{${p.name}}}`, value);
119
+ }
120
+ if (await isBlockedUrl(url)) return {
121
+ ok: false,
122
+ output: "Blocked: cannot make requests to internal network addresses"
123
+ };
124
+ if (!headers["Content-Type"] && body) headers["Content-Type"] = "application/json";
125
+ const fetchOpts = {
126
+ method: handler.method || "GET",
127
+ headers,
128
+ redirect: "manual"
129
+ };
130
+ if (body && handler.method !== "GET" && handler.method !== "HEAD") fetchOpts.body = body;
131
+ const response = await fetch(url, fetchOpts);
132
+ if (response.status >= 300 && response.status < 400) return {
133
+ ok: false,
134
+ output: "Blocked: redirects are not allowed for HTTP custom actions"
135
+ };
136
+ const text = await response.text();
137
+ return {
138
+ ok: response.ok,
139
+ output: text.slice(0, 4e3)
140
+ };
141
+ };
142
+ case "shell": return async (params) => {
143
+ let command = handler.command;
144
+ for (const p of paramDefs) {
145
+ const value = params[p.name] ?? "";
146
+ command = command.replaceAll(`{{${p.name}}}`, shellEscape(value));
147
+ }
148
+ const response = await fetch(`http://localhost:${API_PORT}/api/terminal/run`, {
149
+ method: "POST",
150
+ headers: (() => {
151
+ const headers = { "Content-Type": "application/json" };
152
+ const token = process.env.MILADY_API_TOKEN?.trim();
153
+ if (token) headers.Authorization = /^Bearer\s+/i.test(token) ? token : `Bearer ${token}`;
154
+ return headers;
155
+ })(),
156
+ body: JSON.stringify({
157
+ command,
158
+ clientId: "runtime-shell-action"
159
+ })
160
+ });
161
+ if (!response.ok) return {
162
+ ok: false,
163
+ output: `Terminal request failed: HTTP ${response.status}`
164
+ };
165
+ return {
166
+ ok: true,
167
+ output: `Executed: ${command}`
168
+ };
169
+ };
170
+ case "code": return async (params) => {
171
+ const result = await runCodeHandler(handler.code, params);
172
+ return {
173
+ ok: true,
174
+ output: (result !== void 0 ? String(result) : "Done").slice(0, 4e3)
175
+ };
176
+ };
177
+ default: return async () => ({
178
+ ok: false,
179
+ output: "Unknown handler type"
180
+ });
181
+ }
182
+ }
183
+ /**
184
+ * Convert a single CustomActionDef into an ElizaOS Action.
185
+ */
186
+ function defToAction(def) {
187
+ const handler = buildHandler(def.handler, def.parameters);
188
+ return {
189
+ name: def.name,
190
+ similes: def.similes ?? [],
191
+ description: def.description,
192
+ validate: async () => true,
193
+ handler: async (_runtime, _message, _state, options) => {
194
+ try {
195
+ const opts = options;
196
+ const params = {};
197
+ for (const p of def.parameters) {
198
+ const value = opts?.parameters?.[p.name];
199
+ if (typeof value === "string") params[p.name] = value;
200
+ else if (value !== void 0 && value !== null) params[p.name] = String(value);
201
+ else if (p.required) return {
202
+ text: `Missing required parameter: ${p.name}`,
203
+ success: false
204
+ };
205
+ }
206
+ const result = await handler(params);
207
+ return {
208
+ text: result.output,
209
+ success: result.ok,
210
+ data: {
211
+ actionId: def.id,
212
+ params
213
+ }
214
+ };
215
+ } catch (err) {
216
+ return {
217
+ text: `Action failed: ${err instanceof Error ? err.message : String(err)}`,
218
+ success: false
219
+ };
220
+ }
221
+ },
222
+ parameters: def.parameters.map((p) => ({
223
+ name: p.name,
224
+ description: p.description,
225
+ required: p.required,
226
+ schema: { type: "string" }
227
+ }))
228
+ };
229
+ }
230
+ /**
231
+ * Load custom actions from config and convert them to ElizaOS Action objects.
232
+ * Only returns enabled actions.
233
+ */
234
+ function loadCustomActions() {
235
+ try {
236
+ return (loadMiladyConfig().customActions ?? []).filter((d) => d.enabled).map(defToAction);
237
+ } catch {
238
+ return [];
239
+ }
240
+ }
241
+ /**
242
+ * Build a temporary handler for testing a custom action definition.
243
+ * Used by the test endpoint to execute an action with sample params.
244
+ */
245
+ function buildTestHandler(def) {
246
+ return buildHandler(def.handler, def.parameters);
247
+ }
248
+
249
+ //#endregion
250
+ export { buildTestHandler, loadCustomActions, registerCustomActionLive, setCustomActionsRuntime };