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.
- package/dist/_virtual/_rolldown/runtime.js +7 -0
- package/dist/actions/emote.js +64 -0
- package/dist/actions/restart.js +81 -0
- package/dist/actions/send-message.js +152 -0
- package/dist/agent-admin-routes.js +82 -0
- package/dist/agent-lifecycle-routes.js +79 -0
- package/dist/agent-transfer-routes.js +102 -0
- package/dist/api/agent-admin-routes.js +82 -0
- package/dist/api/agent-lifecycle-routes.js +79 -0
- package/dist/api/agent-transfer-routes.js +102 -0
- package/dist/api/apps-hyperscape-routes.js +58 -0
- package/dist/api/apps-routes.js +114 -0
- package/dist/api/auth-routes.js +56 -0
- package/dist/api/autonomy-routes.js +44 -0
- package/dist/api/bug-report-routes.js +111 -0
- package/dist/api/character-routes.js +195 -0
- package/dist/api/cloud-routes.js +330 -0
- package/dist/api/cloud-status-routes.js +155 -0
- package/dist/api/compat-utils.js +111 -0
- package/dist/api/database.js +735 -0
- package/dist/api/diagnostics-routes.js +205 -0
- package/dist/api/drop-service.js +134 -0
- package/dist/api/early-logs.js +86 -0
- package/dist/api/http-helpers.js +131 -0
- package/dist/api/knowledge-routes.js +534 -0
- package/dist/api/memory-bounds.js +71 -0
- package/dist/api/models-routes.js +28 -0
- package/dist/api/og-tracker.js +36 -0
- package/dist/api/permissions-routes.js +109 -0
- package/dist/api/plugin-validation.js +198 -0
- package/dist/api/provider-switch-config.js +41 -0
- package/dist/api/registry-routes.js +86 -0
- package/dist/api/registry-service.js +164 -0
- package/dist/api/sandbox-routes.js +1112 -0
- package/dist/api/server.js +7949 -0
- package/dist/api/subscription-routes.js +172 -0
- package/dist/api/terminal-run-limits.js +24 -0
- package/dist/api/training-routes.js +158 -0
- package/dist/api/trajectory-routes.js +300 -0
- package/dist/api/trigger-routes.js +246 -0
- package/dist/api/twitter-verify.js +134 -0
- package/dist/api/tx-service.js +108 -0
- package/dist/api/wallet-routes.js +266 -0
- package/dist/api/wallet.js +568 -0
- package/dist/api/whatsapp-routes.js +182 -0
- package/dist/api/zip-utils.js +109 -0
- package/dist/apps-hyperscape-routes.js +58 -0
- package/dist/apps-routes.js +114 -0
- package/dist/ascii.js +20 -0
- package/dist/auth/anthropic.js +44 -0
- package/dist/auth/apply-stealth.js +41 -0
- package/dist/auth/claude-code-stealth.js +78 -0
- package/dist/auth/credentials.js +156 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/openai-codex.js +66 -0
- package/dist/auth/types.js +9 -0
- package/dist/auth-routes.js +56 -0
- package/dist/autonomy-routes.js +44 -0
- package/dist/bug-report-routes.js +111 -0
- package/dist/build-info.json +6 -0
- package/dist/character-routes.js +195 -0
- package/dist/cli/argv.js +63 -0
- package/dist/cli/banner.js +34 -0
- package/dist/cli/cli-name.js +21 -0
- package/dist/cli/cli-utils.js +16 -0
- package/dist/cli/git-commit.js +78 -0
- package/dist/cli/parse-duration.js +15 -0
- package/dist/cli/plugins-cli.js +590 -0
- package/dist/cli/profile-utils.js +9 -0
- package/dist/cli/profile.js +95 -0
- package/dist/cli/program/build-program.js +17 -0
- package/dist/cli/program/command-registry.js +23 -0
- package/dist/cli/program/help.js +47 -0
- package/dist/cli/program/preaction.js +33 -0
- package/dist/cli/program/register.config.js +106 -0
- package/dist/cli/program/register.configure.js +20 -0
- package/dist/cli/program/register.dashboard.js +124 -0
- package/dist/cli/program/register.models.js +23 -0
- package/dist/cli/program/register.setup.js +36 -0
- package/dist/cli/program/register.start.js +22 -0
- package/dist/cli/program/register.subclis.js +70 -0
- package/dist/cli/program/register.tui.js +163 -0
- package/dist/cli/program/register.update.js +154 -0
- package/dist/cli/program.js +3 -0
- package/dist/cli/run-main.js +37 -0
- package/dist/cli/version.js +7 -0
- package/dist/cloud/validate-url.js +93 -0
- package/dist/cloud-routes.js +330 -0
- package/dist/cloud-status-routes.js +155 -0
- package/dist/compat-utils.js +111 -0
- package/dist/config/config.js +69 -0
- package/dist/config/env-vars.js +19 -0
- package/dist/config/includes.js +121 -0
- package/dist/config/object-utils.js +7 -0
- package/dist/config/paths.js +38 -0
- package/dist/config/plugin-auto-enable.js +231 -0
- package/dist/config/schema.js +864 -0
- package/dist/config/telegram-custom-commands.js +76 -0
- package/dist/config/zod-schema.agent-runtime.js +519 -0
- package/dist/config/zod-schema.core.js +538 -0
- package/dist/config/zod-schema.hooks.js +103 -0
- package/dist/config/zod-schema.js +488 -0
- package/dist/config/zod-schema.providers-core.js +785 -0
- package/dist/config/zod-schema.session.js +73 -0
- package/dist/core-plugins.js +37 -0
- package/dist/custom-actions.js +250 -0
- package/dist/database.js +735 -0
- package/dist/diagnostics/integration-observability.js +57 -0
- package/dist/diagnostics-routes.js +205 -0
- package/dist/drop-service.js +134 -0
- package/dist/early-logs.js +24 -0
- package/dist/eliza.js +2061 -0
- package/dist/emotes/catalog.js +271 -0
- package/dist/entry.js +40 -0
- package/dist/hooks/discovery.js +167 -0
- package/dist/hooks/eligibility.js +64 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/loader.js +147 -0
- package/dist/hooks/registry.js +55 -0
- package/dist/http-helpers.js +131 -0
- package/dist/index.js +49 -0
- package/dist/knowledge-routes.js +534 -0
- package/dist/memory-bounds.js +71 -0
- package/dist/milady-plugin.js +90 -0
- package/dist/models-routes.js +28 -0
- package/dist/onboarding-names.js +78 -0
- package/dist/onboarding-presets.js +922 -0
- package/dist/package.json +1 -0
- package/dist/permissions-routes.js +109 -0
- package/dist/plugin-validation.js +107 -0
- package/dist/plugins/whatsapp/actions.js +91 -0
- package/dist/plugins/whatsapp/index.js +16 -0
- package/dist/plugins/whatsapp/service.js +270 -0
- package/dist/provider-switch-config.js +41 -0
- package/dist/providers/admin-trust.js +46 -0
- package/dist/providers/autonomous-state.js +101 -0
- package/dist/providers/session-bridge.js +86 -0
- package/dist/providers/session-utils.js +36 -0
- package/dist/providers/simple-mode.js +50 -0
- package/dist/providers/ui-catalog.js +15 -0
- package/dist/providers/workspace-provider.js +93 -0
- package/dist/providers/workspace.js +348 -0
- package/dist/registry-routes.js +86 -0
- package/dist/registry-service.js +164 -0
- package/dist/restart.js +40 -0
- package/dist/runtime/core-plugins.js +37 -0
- package/dist/runtime/custom-actions.js +250 -0
- package/dist/runtime/eliza.js +2061 -0
- package/dist/runtime/embedding-manager-support.js +185 -0
- package/dist/runtime/embedding-manager.js +193 -0
- package/dist/runtime/embedding-presets.js +54 -0
- package/dist/runtime/embedding-state.js +8 -0
- package/dist/runtime/milady-plugin.js +90 -0
- package/dist/runtime/onboarding-names.js +78 -0
- package/dist/runtime/restart.js +40 -0
- package/dist/runtime/version.js +7 -0
- package/dist/sandbox-routes.js +1112 -0
- package/dist/security/audit-log.js +149 -0
- package/dist/security/network-policy.js +70 -0
- package/dist/server.js +7949 -0
- package/dist/services/agent-export.js +559 -0
- package/dist/services/app-manager.js +389 -0
- package/dist/services/browser-capture.js +86 -0
- package/dist/services/fallback-training-service.js +128 -0
- package/dist/services/mcp-marketplace.js +134 -0
- package/dist/services/plugin-installer.js +396 -0
- package/dist/services/plugin-manager-types.js +15 -0
- package/dist/services/registry-client-app-meta.js +144 -0
- package/dist/services/registry-client-endpoints.js +166 -0
- package/dist/services/registry-client-local.js +271 -0
- package/dist/services/registry-client-network.js +93 -0
- package/dist/services/registry-client-queries.js +70 -0
- package/dist/services/registry-client.js +157 -0
- package/dist/services/sandbox-engine.js +511 -0
- package/dist/services/sandbox-manager.js +297 -0
- package/dist/services/self-updater.js +175 -0
- package/dist/services/skill-catalog-client.js +119 -0
- package/dist/services/skill-marketplace.js +521 -0
- package/dist/services/stream-manager.js +236 -0
- package/dist/services/update-checker.js +121 -0
- package/dist/services/update-notifier.js +29 -0
- package/dist/services/version-compat.js +78 -0
- package/dist/services/whatsapp-pairing.js +196 -0
- package/dist/shared/ui-catalog-prompt.js +728 -0
- package/dist/subscription-routes.js +172 -0
- package/dist/terminal/links.js +19 -0
- package/dist/terminal/palette.js +14 -0
- package/dist/terminal/theme.js +25 -0
- package/dist/terminal-run-limits.js +24 -0
- package/dist/training-routes.js +158 -0
- package/dist/trajectory-routes.js +300 -0
- package/dist/trigger-routes.js +246 -0
- package/dist/triggers/action.js +218 -0
- package/dist/triggers/runtime.js +281 -0
- package/dist/triggers/scheduling.js +295 -0
- package/dist/triggers/types.js +5 -0
- package/dist/tui/components/assistant-message.js +76 -0
- package/dist/tui/components/chat-editor.js +34 -0
- package/dist/tui/components/embeddings-overlay.js +46 -0
- package/dist/tui/components/footer.js +60 -0
- package/dist/tui/components/index.js +15 -0
- package/dist/tui/components/modal-frame.js +45 -0
- package/dist/tui/components/modal-style.js +15 -0
- package/dist/tui/components/model-selector.js +70 -0
- package/dist/tui/components/pinned-chat-layout.js +46 -0
- package/dist/tui/components/plugins-endpoints-tab.js +196 -0
- package/dist/tui/components/plugins-installed-tab-view.js +69 -0
- package/dist/tui/components/plugins-installed-tab.js +319 -0
- package/dist/tui/components/plugins-overlay-catalog.js +81 -0
- package/dist/tui/components/plugins-overlay-data-api.js +21 -0
- package/dist/tui/components/plugins-overlay-data-shared.js +20 -0
- package/dist/tui/components/plugins-overlay-data.js +323 -0
- package/dist/tui/components/plugins-overlay.js +117 -0
- package/dist/tui/components/plugins-store-tab.js +148 -0
- package/dist/tui/components/settings-overlay.js +61 -0
- package/dist/tui/components/status-bar.js +64 -0
- package/dist/tui/components/tool-execution.js +68 -0
- package/dist/tui/components/user-message.js +22 -0
- package/dist/tui/eliza-tui-bridge.js +606 -0
- package/dist/tui/index.js +370 -0
- package/dist/tui/modal-presets.js +33 -0
- package/dist/tui/model-spec.js +46 -0
- package/dist/tui/sse-parser.js +78 -0
- package/dist/tui/theme.js +110 -0
- package/dist/tui/titlebar-spinner.js +62 -0
- package/dist/tui/tui-app.js +311 -0
- package/dist/tui/ws-client.js +215 -0
- package/dist/twitter-verify.js +134 -0
- package/dist/tx-service.js +108 -0
- package/dist/utils/exec-safety.js +17 -0
- package/dist/utils/globals.js +20 -0
- package/dist/utils/milady-root.js +61 -0
- package/dist/utils/number-parsing.js +37 -0
- package/dist/version-resolver.js +37 -0
- package/dist/version.js +7 -0
- package/dist/wallet-routes.js +266 -0
- package/dist/wallet.js +568 -0
- package/dist/whatsapp-routes.js +182 -0
- package/dist/zip-utils.js +109 -0
- package/milady.mjs +14 -0
- package/package.json +111 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { GroupChatSchema, InboundDebounceSchema, MessagePolicySchema, NativeCommandsSettingSchema, QueueSchema, TtsConfigSchema } from "./zod-schema.core.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/config/zod-schema.session.ts
|
|
5
|
+
const SessionResetConfigSchema = z.object({
|
|
6
|
+
mode: z.union([z.literal("daily"), z.literal("idle")]).optional(),
|
|
7
|
+
atHour: z.number().int().min(0).max(23).optional(),
|
|
8
|
+
idleMinutes: z.number().int().positive().optional()
|
|
9
|
+
}).strict();
|
|
10
|
+
const SessionSendPolicySchema = MessagePolicySchema;
|
|
11
|
+
const SessionSchema = z.object({
|
|
12
|
+
scope: z.union([z.literal("per-sender"), z.literal("global")]).optional(),
|
|
13
|
+
dmScope: z.union([
|
|
14
|
+
z.literal("main"),
|
|
15
|
+
z.literal("per-peer"),
|
|
16
|
+
z.literal("per-channel-peer"),
|
|
17
|
+
z.literal("per-account-channel-peer")
|
|
18
|
+
]).optional(),
|
|
19
|
+
identityLinks: z.record(z.string(), z.array(z.string())).optional(),
|
|
20
|
+
resetTriggers: z.array(z.string()).optional(),
|
|
21
|
+
idleMinutes: z.number().int().positive().optional(),
|
|
22
|
+
reset: SessionResetConfigSchema.optional(),
|
|
23
|
+
resetByType: z.object({
|
|
24
|
+
dm: SessionResetConfigSchema.optional(),
|
|
25
|
+
group: SessionResetConfigSchema.optional(),
|
|
26
|
+
thread: SessionResetConfigSchema.optional()
|
|
27
|
+
}).strict().optional(),
|
|
28
|
+
resetByChannel: z.record(z.string(), SessionResetConfigSchema).optional(),
|
|
29
|
+
store: z.string().optional(),
|
|
30
|
+
typingIntervalSeconds: z.number().int().positive().optional(),
|
|
31
|
+
typingMode: z.union([
|
|
32
|
+
z.literal("never"),
|
|
33
|
+
z.literal("instant"),
|
|
34
|
+
z.literal("thinking"),
|
|
35
|
+
z.literal("message")
|
|
36
|
+
]).optional(),
|
|
37
|
+
mainKey: z.string().optional(),
|
|
38
|
+
sendPolicy: SessionSendPolicySchema.optional(),
|
|
39
|
+
agentToAgent: z.object({ maxPingPongTurns: z.number().int().min(0).max(5).optional() }).strict().optional()
|
|
40
|
+
}).strict().optional();
|
|
41
|
+
const MessagesSchema = z.object({
|
|
42
|
+
messagePrefix: z.string().optional(),
|
|
43
|
+
responsePrefix: z.string().optional(),
|
|
44
|
+
groupChat: GroupChatSchema,
|
|
45
|
+
queue: QueueSchema,
|
|
46
|
+
inbound: InboundDebounceSchema,
|
|
47
|
+
ackReaction: z.string().optional(),
|
|
48
|
+
ackReactionScope: z.enum([
|
|
49
|
+
"group-mentions",
|
|
50
|
+
"group-all",
|
|
51
|
+
"direct",
|
|
52
|
+
"all"
|
|
53
|
+
]).optional(),
|
|
54
|
+
removeAckAfterReply: z.boolean().optional(),
|
|
55
|
+
tts: TtsConfigSchema
|
|
56
|
+
}).strict().optional();
|
|
57
|
+
const CommandsSchema = z.object({
|
|
58
|
+
native: NativeCommandsSettingSchema.optional().default("auto"),
|
|
59
|
+
nativeSkills: NativeCommandsSettingSchema.optional().default("auto"),
|
|
60
|
+
text: z.boolean().optional(),
|
|
61
|
+
bash: z.boolean().optional(),
|
|
62
|
+
bashForegroundMs: z.number().int().min(0).max(3e4).optional(),
|
|
63
|
+
config: z.boolean().optional(),
|
|
64
|
+
debug: z.boolean().optional(),
|
|
65
|
+
restart: z.boolean().optional(),
|
|
66
|
+
useAccessGroups: z.boolean().optional()
|
|
67
|
+
}).strict().optional().default({
|
|
68
|
+
native: "auto",
|
|
69
|
+
nativeSkills: "auto"
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { CommandsSchema, MessagesSchema, SessionSchema, SessionSendPolicySchema };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/runtime/core-plugins.ts
|
|
2
|
+
/**
|
|
3
|
+
* Core plugin package lists shared by runtime startup and the API server.
|
|
4
|
+
*
|
|
5
|
+
* Keeping this in a standalone module avoids a circular dependency between
|
|
6
|
+
* `api/server.ts` and `runtime/eliza.ts`.
|
|
7
|
+
*/
|
|
8
|
+
/** Core plugins that should always be loaded. */
|
|
9
|
+
const CORE_PLUGINS = [
|
|
10
|
+
"@elizaos/plugin-sql",
|
|
11
|
+
"@elizaos/plugin-local-embedding",
|
|
12
|
+
"@elizaos/plugin-secrets-manager",
|
|
13
|
+
"@elizaos/plugin-form",
|
|
14
|
+
"@elizaos/plugin-knowledge",
|
|
15
|
+
"@elizaos/plugin-rolodex",
|
|
16
|
+
"@elizaos/plugin-trajectory-logger",
|
|
17
|
+
"@elizaos/plugin-agent-orchestrator",
|
|
18
|
+
"@elizaos/plugin-cron",
|
|
19
|
+
"@elizaos/plugin-shell",
|
|
20
|
+
"@elizaos/plugin-plugin-manager",
|
|
21
|
+
"@elizaos/plugin-agent-skills",
|
|
22
|
+
"@elizaos/plugin-pdf"
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Plugins that can be enabled from the admin panel.
|
|
26
|
+
* Not loaded by default — kept separate due to packaging or spec issues.
|
|
27
|
+
*/
|
|
28
|
+
const OPTIONAL_CORE_PLUGINS = [
|
|
29
|
+
"@elizaos/plugin-cua",
|
|
30
|
+
"@elizaos/plugin-obsidian",
|
|
31
|
+
"@elizaos/plugin-code",
|
|
32
|
+
"@elizaos/plugin-repoprompt",
|
|
33
|
+
"@milaidy/plugin-claude-code-workbench"
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { CORE_PLUGINS, OPTIONAL_CORE_PLUGINS };
|
|
@@ -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 };
|