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,64 @@
|
|
|
1
|
+
import { EMOTE_BY_ID } from "../emotes/catalog.js";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/emote.ts
|
|
4
|
+
/** API port for posting emote requests. */
|
|
5
|
+
const API_PORT = process.env.API_PORT || process.env.SERVER_PORT || "2138";
|
|
6
|
+
const emoteAction = {
|
|
7
|
+
name: "PLAY_EMOTE",
|
|
8
|
+
similes: [
|
|
9
|
+
"EMOTE",
|
|
10
|
+
"ANIMATE",
|
|
11
|
+
"GESTURE",
|
|
12
|
+
"DANCE",
|
|
13
|
+
"WAVE",
|
|
14
|
+
"PLAY_ANIMATION",
|
|
15
|
+
"DO_EMOTE",
|
|
16
|
+
"PERFORM"
|
|
17
|
+
],
|
|
18
|
+
description: "Play an emote animation on the avatar. Emotes are visual gestures or animations that express emotion or action (e.g., wave, dance, cheer).",
|
|
19
|
+
validate: async (_runtime, _message, _state) => {
|
|
20
|
+
return true;
|
|
21
|
+
},
|
|
22
|
+
handler: async (_runtime, _message, _state, options) => {
|
|
23
|
+
try {
|
|
24
|
+
const params = options?.parameters;
|
|
25
|
+
const emoteId = typeof params?.emote === "string" ? params.emote : void 0;
|
|
26
|
+
if (!emoteId) return {
|
|
27
|
+
text: "",
|
|
28
|
+
success: false
|
|
29
|
+
};
|
|
30
|
+
const emote = EMOTE_BY_ID.get(emoteId);
|
|
31
|
+
if (!emote) return {
|
|
32
|
+
text: "",
|
|
33
|
+
success: false
|
|
34
|
+
};
|
|
35
|
+
if (!(await fetch(`http://localhost:${API_PORT}/api/emote`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: { "Content-Type": "application/json" },
|
|
38
|
+
body: JSON.stringify({ emoteId: emote.id })
|
|
39
|
+
})).ok) return {
|
|
40
|
+
text: "",
|
|
41
|
+
success: false
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
text: `*${emote.name.toLowerCase()}s*`,
|
|
45
|
+
success: true,
|
|
46
|
+
data: { emoteId: emote.id }
|
|
47
|
+
};
|
|
48
|
+
} catch (_err) {
|
|
49
|
+
return {
|
|
50
|
+
text: "",
|
|
51
|
+
success: false
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
parameters: [{
|
|
56
|
+
name: "emote",
|
|
57
|
+
description: "The emote ID to play",
|
|
58
|
+
required: true,
|
|
59
|
+
schema: { type: "string" }
|
|
60
|
+
}]
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { emoteAction };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { requestRestart } from "../runtime/restart.js";
|
|
2
|
+
import { logger } from "@elizaos/core";
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
|
|
5
|
+
//#region src/actions/restart.ts
|
|
6
|
+
/**
|
|
7
|
+
* RESTART_AGENT action — gracefully restarts the agent.
|
|
8
|
+
*
|
|
9
|
+
* When triggered the action:
|
|
10
|
+
* 1. Persists a "Restarting…" memory so the event is visible in logs
|
|
11
|
+
* 2. Returns a brief restart notice to the caller
|
|
12
|
+
* 3. After a short delay (so the response can flush), invokes
|
|
13
|
+
* {@link requestRestart} which delegates to the registered
|
|
14
|
+
* {@link RestartHandler}.
|
|
15
|
+
*
|
|
16
|
+
* In CLI mode the default handler exits with code 75 so the runner script
|
|
17
|
+
* rebuilds and relaunches. In headless / Electron mode a custom handler
|
|
18
|
+
* performs an in-process restart (stop → re-init → hot-swap references).
|
|
19
|
+
*
|
|
20
|
+
* @module actions/restart
|
|
21
|
+
*/
|
|
22
|
+
/** Small delay (ms) before restarting so the response has time to flush. */
|
|
23
|
+
const SHUTDOWN_DELAY_MS = 1500;
|
|
24
|
+
const restartAction = {
|
|
25
|
+
name: "RESTART_AGENT",
|
|
26
|
+
similes: [
|
|
27
|
+
"RESTART",
|
|
28
|
+
"REBOOT",
|
|
29
|
+
"RELOAD",
|
|
30
|
+
"REFRESH",
|
|
31
|
+
"RESPAWN",
|
|
32
|
+
"RESTART_SELF",
|
|
33
|
+
"REBOOT_AGENT",
|
|
34
|
+
"RELOAD_AGENT"
|
|
35
|
+
],
|
|
36
|
+
description: "Restart the agent process. This stops the runtime, rebuilds if source files changed, and relaunches — picking up new code, config, or plugins.",
|
|
37
|
+
validate: async (_runtime, _message, _state) => {
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
handler: async (runtime, message, _state, options) => {
|
|
41
|
+
const params = options?.parameters;
|
|
42
|
+
const reason = typeof params?.reason === "string" ? params.reason : void 0;
|
|
43
|
+
const restartText = reason ? `Restarting… (${reason})` : "Restarting…";
|
|
44
|
+
logger.info(`[milady] ${restartText}`);
|
|
45
|
+
try {
|
|
46
|
+
const restartMemory = {
|
|
47
|
+
id: crypto.randomUUID(),
|
|
48
|
+
entityId: runtime.agentId,
|
|
49
|
+
roomId: message.roomId,
|
|
50
|
+
worldId: message.worldId,
|
|
51
|
+
content: {
|
|
52
|
+
text: restartText,
|
|
53
|
+
source: "milady",
|
|
54
|
+
type: "system"
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
await runtime.createMemory(restartMemory, "messages");
|
|
58
|
+
} catch (err) {
|
|
59
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
60
|
+
logger.warn(`[milady] Could not persist restart memory: ${msg}`);
|
|
61
|
+
}
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
requestRestart(reason);
|
|
64
|
+
}, SHUTDOWN_DELAY_MS);
|
|
65
|
+
return {
|
|
66
|
+
text: restartText,
|
|
67
|
+
success: true,
|
|
68
|
+
values: { restarting: true },
|
|
69
|
+
data: { reason }
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
parameters: [{
|
|
73
|
+
name: "reason",
|
|
74
|
+
description: "Optional reason for the restart (logged for diagnostics).",
|
|
75
|
+
required: false,
|
|
76
|
+
schema: { type: "string" }
|
|
77
|
+
}]
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { restartAction };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
//#region src/actions/send-message.ts
|
|
2
|
+
const sendMessageAction = {
|
|
3
|
+
name: "SEND_MESSAGE",
|
|
4
|
+
similes: [
|
|
5
|
+
"DM",
|
|
6
|
+
"MESSAGE",
|
|
7
|
+
"SEND_DM",
|
|
8
|
+
"POST_MESSAGE"
|
|
9
|
+
],
|
|
10
|
+
description: "Send a message to a user or room on a specific platform/service using explicit parameters.",
|
|
11
|
+
validate: async () => true,
|
|
12
|
+
handler: async (runtime, _message, _state, options) => {
|
|
13
|
+
const params = options?.parameters;
|
|
14
|
+
const targetType = params?.targetType === "user" || params?.targetType === "room" ? params.targetType : null;
|
|
15
|
+
const source = typeof params?.source === "string" ? params.source.trim() : "";
|
|
16
|
+
const target = typeof params?.target === "string" ? params.target.trim() : "";
|
|
17
|
+
const text = typeof params?.text === "string" ? params.text.trim() : "";
|
|
18
|
+
if (!targetType || !source || !target || !text) return {
|
|
19
|
+
text: "SEND_MESSAGE requires targetType, source, target, and text parameters.",
|
|
20
|
+
success: false,
|
|
21
|
+
values: {
|
|
22
|
+
success: false,
|
|
23
|
+
error: "INVALID_PARAMETERS"
|
|
24
|
+
},
|
|
25
|
+
data: {
|
|
26
|
+
actionName: "SEND_MESSAGE",
|
|
27
|
+
targetType,
|
|
28
|
+
source: source || null,
|
|
29
|
+
target: target || null
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const service = runtime.getService(source);
|
|
33
|
+
if (!service) return {
|
|
34
|
+
text: `Message service '${source}' is not available.`,
|
|
35
|
+
success: false,
|
|
36
|
+
values: {
|
|
37
|
+
success: false,
|
|
38
|
+
error: "SERVICE_NOT_FOUND"
|
|
39
|
+
},
|
|
40
|
+
data: {
|
|
41
|
+
actionName: "SEND_MESSAGE",
|
|
42
|
+
targetType,
|
|
43
|
+
source,
|
|
44
|
+
target
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
if (targetType === "user") {
|
|
48
|
+
if (!service.sendDirectMessage) return {
|
|
49
|
+
text: `Direct messaging is not supported by '${source}'.`,
|
|
50
|
+
success: false,
|
|
51
|
+
values: {
|
|
52
|
+
success: false,
|
|
53
|
+
error: "DIRECT_MESSAGE_UNSUPPORTED"
|
|
54
|
+
},
|
|
55
|
+
data: {
|
|
56
|
+
actionName: "SEND_MESSAGE",
|
|
57
|
+
targetType,
|
|
58
|
+
source,
|
|
59
|
+
target
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
await service.sendDirectMessage(target, {
|
|
63
|
+
text,
|
|
64
|
+
source
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
text: `Message sent to user ${target} on ${source}.`,
|
|
68
|
+
success: true,
|
|
69
|
+
values: {
|
|
70
|
+
success: true,
|
|
71
|
+
targetType,
|
|
72
|
+
source,
|
|
73
|
+
target
|
|
74
|
+
},
|
|
75
|
+
data: {
|
|
76
|
+
actionName: "SEND_MESSAGE",
|
|
77
|
+
targetType,
|
|
78
|
+
source,
|
|
79
|
+
target,
|
|
80
|
+
text
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!service.sendRoomMessage) return {
|
|
85
|
+
text: `Room messaging is not supported by '${source}'.`,
|
|
86
|
+
success: false,
|
|
87
|
+
values: {
|
|
88
|
+
success: false,
|
|
89
|
+
error: "ROOM_MESSAGE_UNSUPPORTED"
|
|
90
|
+
},
|
|
91
|
+
data: {
|
|
92
|
+
actionName: "SEND_MESSAGE",
|
|
93
|
+
targetType,
|
|
94
|
+
source,
|
|
95
|
+
target
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
await service.sendRoomMessage(target, {
|
|
99
|
+
text,
|
|
100
|
+
source
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
text: `Message sent to room ${target} on ${source}.`,
|
|
104
|
+
success: true,
|
|
105
|
+
values: {
|
|
106
|
+
success: true,
|
|
107
|
+
targetType,
|
|
108
|
+
source,
|
|
109
|
+
target
|
|
110
|
+
},
|
|
111
|
+
data: {
|
|
112
|
+
actionName: "SEND_MESSAGE",
|
|
113
|
+
targetType,
|
|
114
|
+
source,
|
|
115
|
+
target,
|
|
116
|
+
text
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
parameters: [
|
|
121
|
+
{
|
|
122
|
+
name: "targetType",
|
|
123
|
+
description: "Target entity type: user or room.",
|
|
124
|
+
required: true,
|
|
125
|
+
schema: {
|
|
126
|
+
type: "string",
|
|
127
|
+
enum: ["user", "room"]
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "source",
|
|
132
|
+
description: "Messaging source/service name (e.g. telegram, discord).",
|
|
133
|
+
required: true,
|
|
134
|
+
schema: { type: "string" }
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "target",
|
|
138
|
+
description: "Target identifier. For users: entity ID/username. For rooms: room ID/name.",
|
|
139
|
+
required: true,
|
|
140
|
+
schema: { type: "string" }
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "text",
|
|
144
|
+
description: "Message text to send.",
|
|
145
|
+
required: true,
|
|
146
|
+
schema: { type: "string" }
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
export { sendMessageAction };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/api/agent-admin-routes.ts
|
|
2
|
+
async function handleAgentAdminRoutes(ctx) {
|
|
3
|
+
const { res, method, pathname, state, onRestart, json, error, resolveStateDir, resolvePath, getHomeDir, isSafeResetStateDir, stateDirExists, removeStateDir, logWarn } = ctx;
|
|
4
|
+
if (method === "POST" && pathname === "/api/agent/restart") {
|
|
5
|
+
if (!onRestart) {
|
|
6
|
+
error(res, "Restart is not supported in this mode (no restart handler registered)", 501);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (state.agentState === "restarting") {
|
|
10
|
+
error(res, "A restart is already in progress", 409);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const previousState = state.agentState;
|
|
14
|
+
state.agentState = "restarting";
|
|
15
|
+
try {
|
|
16
|
+
const newRuntime = await onRestart();
|
|
17
|
+
if (newRuntime) {
|
|
18
|
+
state.runtime = newRuntime;
|
|
19
|
+
state.chatConnectionReady = null;
|
|
20
|
+
state.chatConnectionPromise = null;
|
|
21
|
+
state.agentState = "running";
|
|
22
|
+
state.agentName = newRuntime.character.name ?? "Milady";
|
|
23
|
+
state.startedAt = Date.now();
|
|
24
|
+
state.pendingRestartReasons = [];
|
|
25
|
+
json(res, {
|
|
26
|
+
ok: true,
|
|
27
|
+
pendingRestart: false,
|
|
28
|
+
status: {
|
|
29
|
+
state: state.agentState,
|
|
30
|
+
agentName: state.agentName,
|
|
31
|
+
startedAt: state.startedAt
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
state.agentState = previousState;
|
|
36
|
+
error(res, "Restart handler returned null — runtime failed to re-initialize", 500);
|
|
37
|
+
}
|
|
38
|
+
} catch (err) {
|
|
39
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
40
|
+
state.agentState = previousState;
|
|
41
|
+
error(res, `Restart failed: ${message}`, 500);
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (method === "POST" && pathname === "/api/agent/reset") {
|
|
46
|
+
try {
|
|
47
|
+
if (state.runtime) {
|
|
48
|
+
try {
|
|
49
|
+
await state.runtime.stop();
|
|
50
|
+
} catch (stopErr) {
|
|
51
|
+
logWarn(`[milady-api] Error stopping runtime during reset: ${stopErr instanceof Error ? stopErr.message : String(stopErr)}`);
|
|
52
|
+
}
|
|
53
|
+
state.runtime = null;
|
|
54
|
+
}
|
|
55
|
+
const resolvedState = resolvePath(resolveStateDir());
|
|
56
|
+
if (!isSafeResetStateDir(resolvedState, getHomeDir())) {
|
|
57
|
+
logWarn(`[milady-api] Refusing to delete unsafe state dir: "${resolvedState}"`);
|
|
58
|
+
error(res, `Reset aborted: state directory "${resolvedState}" does not appear safe to delete`, 400);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (stateDirExists(resolvedState)) removeStateDir(resolvedState);
|
|
62
|
+
state.agentState = "stopped";
|
|
63
|
+
state.agentName = "Milady";
|
|
64
|
+
state.model = void 0;
|
|
65
|
+
state.startedAt = void 0;
|
|
66
|
+
state.config = {};
|
|
67
|
+
state.chatRoomId = null;
|
|
68
|
+
state.chatUserId = null;
|
|
69
|
+
state.chatConnectionReady = null;
|
|
70
|
+
state.chatConnectionPromise = null;
|
|
71
|
+
state.pendingRestartReasons = [];
|
|
72
|
+
json(res, { ok: true });
|
|
73
|
+
} catch (err) {
|
|
74
|
+
error(res, `Reset failed: ${err instanceof Error ? err.message : String(err)}`, 500);
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { handleAgentAdminRoutes };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getAutonomySvc } from "./autonomy-routes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/api/agent-lifecycle-routes.ts
|
|
4
|
+
function detectModel(runtime) {
|
|
5
|
+
if (!runtime) return "unknown";
|
|
6
|
+
return runtime.plugins.find((plugin) => plugin.name.includes("anthropic") || plugin.name.includes("openai") || plugin.name.includes("groq"))?.name ?? "unknown";
|
|
7
|
+
}
|
|
8
|
+
async function handleAgentLifecycleRoutes(ctx) {
|
|
9
|
+
const { res, method, pathname, state, json } = ctx;
|
|
10
|
+
if (method === "POST" && pathname === "/api/agent/start") {
|
|
11
|
+
state.agentState = "running";
|
|
12
|
+
state.startedAt = Date.now();
|
|
13
|
+
state.model = detectModel(state.runtime);
|
|
14
|
+
const svc = getAutonomySvc(state.runtime);
|
|
15
|
+
if (svc) await svc.enableAutonomy();
|
|
16
|
+
json(res, {
|
|
17
|
+
ok: true,
|
|
18
|
+
status: {
|
|
19
|
+
state: state.agentState,
|
|
20
|
+
agentName: state.agentName,
|
|
21
|
+
model: state.model,
|
|
22
|
+
uptime: 0,
|
|
23
|
+
startedAt: state.startedAt
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (method === "POST" && pathname === "/api/agent/stop") {
|
|
29
|
+
const svc = getAutonomySvc(state.runtime);
|
|
30
|
+
if (svc) await svc.disableAutonomy();
|
|
31
|
+
state.agentState = "stopped";
|
|
32
|
+
state.startedAt = void 0;
|
|
33
|
+
state.model = void 0;
|
|
34
|
+
json(res, {
|
|
35
|
+
ok: true,
|
|
36
|
+
status: {
|
|
37
|
+
state: state.agentState,
|
|
38
|
+
agentName: state.agentName
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (method === "POST" && pathname === "/api/agent/pause") {
|
|
44
|
+
const svc = getAutonomySvc(state.runtime);
|
|
45
|
+
if (svc) await svc.disableAutonomy();
|
|
46
|
+
state.agentState = "paused";
|
|
47
|
+
json(res, {
|
|
48
|
+
ok: true,
|
|
49
|
+
status: {
|
|
50
|
+
state: state.agentState,
|
|
51
|
+
agentName: state.agentName,
|
|
52
|
+
model: state.model,
|
|
53
|
+
uptime: state.startedAt ? Date.now() - state.startedAt : void 0,
|
|
54
|
+
startedAt: state.startedAt
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (method === "POST" && pathname === "/api/agent/resume") {
|
|
60
|
+
const svc = getAutonomySvc(state.runtime);
|
|
61
|
+
if (svc) await svc.enableAutonomy();
|
|
62
|
+
state.agentState = "running";
|
|
63
|
+
json(res, {
|
|
64
|
+
ok: true,
|
|
65
|
+
status: {
|
|
66
|
+
state: state.agentState,
|
|
67
|
+
agentName: state.agentName,
|
|
68
|
+
model: state.model,
|
|
69
|
+
uptime: state.startedAt ? Date.now() - state.startedAt : void 0,
|
|
70
|
+
startedAt: state.startedAt
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { handleAgentLifecycleRoutes };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { AgentExportError, estimateExportSize, exportAgent, importAgent } from "./services/agent-export.js";
|
|
2
|
+
import { readRequestBodyBuffer } from "./http-helpers.js";
|
|
3
|
+
|
|
4
|
+
//#region src/api/agent-transfer-routes.ts
|
|
5
|
+
const MAX_IMPORT_BYTES = 512 * 1048576;
|
|
6
|
+
const AGENT_TRANSFER_MIN_PASSWORD_LENGTH = 4;
|
|
7
|
+
const AGENT_TRANSFER_MAX_PASSWORD_LENGTH = 1024;
|
|
8
|
+
function readRawBody(req, maxBytes) {
|
|
9
|
+
return readRequestBodyBuffer(req, { maxBytes }).then((body) => {
|
|
10
|
+
if (body === null) throw new Error(`Request body exceeds maximum size (${maxBytes} bytes)`);
|
|
11
|
+
return body;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async function handleAgentTransferRoutes(ctx) {
|
|
15
|
+
const { req, res, method, pathname, state, readJsonBody, json, error } = ctx;
|
|
16
|
+
if (method === "POST" && pathname === "/api/agent/export") {
|
|
17
|
+
if (!state.runtime) {
|
|
18
|
+
error(res, "Agent is not running — start it before exporting.", 503);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const body = await readJsonBody(req, res);
|
|
22
|
+
if (!body) return true;
|
|
23
|
+
if (!body.password || typeof body.password !== "string") {
|
|
24
|
+
error(res, `A password of at least ${AGENT_TRANSFER_MIN_PASSWORD_LENGTH} characters is required.`, 400);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (body.password.length < AGENT_TRANSFER_MIN_PASSWORD_LENGTH) {
|
|
28
|
+
error(res, `A password of at least ${AGENT_TRANSFER_MIN_PASSWORD_LENGTH} characters is required.`, 400);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const fileBuffer = await exportAgent(state.runtime, body.password, { includeLogs: body.includeLogs === true });
|
|
33
|
+
const filename = `${(state.runtime.character.name ?? "agent").replace(/[^a-zA-Z0-9_-]/g, "_").toLowerCase()}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19)}.eliza-agent`;
|
|
34
|
+
res.statusCode = 200;
|
|
35
|
+
res.setHeader("Content-Type", "application/octet-stream");
|
|
36
|
+
res.setHeader("Content-Disposition", `attachment; filename="${filename}"`);
|
|
37
|
+
res.setHeader("Content-Length", fileBuffer.length);
|
|
38
|
+
res.end(fileBuffer);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
+
if (err instanceof AgentExportError) error(res, message, 400);
|
|
42
|
+
else error(res, `Export failed: ${message}`, 500);
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (method === "GET" && pathname === "/api/agent/export/estimate") {
|
|
47
|
+
if (!state.runtime) {
|
|
48
|
+
error(res, "Agent is not running.", 503);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
json(res, await estimateExportSize(state.runtime));
|
|
53
|
+
} catch (err) {
|
|
54
|
+
error(res, `Estimate failed: ${err instanceof Error ? err.message : String(err)}`, 500);
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (method === "POST" && pathname === "/api/agent/import") {
|
|
59
|
+
if (!state.runtime) {
|
|
60
|
+
error(res, "Agent is not running — start it before importing.", 503);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
let rawBody;
|
|
64
|
+
try {
|
|
65
|
+
rawBody = await readRawBody(req, MAX_IMPORT_BYTES);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
error(res, err instanceof Error ? err.message : String(err), 413);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (rawBody.length < 5) {
|
|
71
|
+
error(res, "Request body is too small — expected password + file data.", 400);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
const passwordLength = rawBody.readUInt32BE(0);
|
|
75
|
+
if (passwordLength < AGENT_TRANSFER_MIN_PASSWORD_LENGTH) {
|
|
76
|
+
error(res, `Password must be at least ${AGENT_TRANSFER_MIN_PASSWORD_LENGTH} characters.`, 400);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (passwordLength > AGENT_TRANSFER_MAX_PASSWORD_LENGTH) {
|
|
80
|
+
error(res, `Password is too long (max ${AGENT_TRANSFER_MAX_PASSWORD_LENGTH} bytes).`, 400);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (rawBody.length < 4 + passwordLength + 1) {
|
|
84
|
+
error(res, "Request body is incomplete — missing file data after password.", 400);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
const password = rawBody.subarray(4, 4 + passwordLength).toString("utf-8");
|
|
88
|
+
const fileBuffer = rawBody.subarray(4 + passwordLength);
|
|
89
|
+
try {
|
|
90
|
+
json(res, await importAgent(state.runtime, fileBuffer, password));
|
|
91
|
+
} catch (err) {
|
|
92
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
93
|
+
if (err instanceof AgentExportError) error(res, message, 400);
|
|
94
|
+
else error(res, `Import failed: ${message}`, 500);
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
export { handleAgentTransferRoutes };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/api/agent-admin-routes.ts
|
|
2
|
+
async function handleAgentAdminRoutes(ctx) {
|
|
3
|
+
const { res, method, pathname, state, onRestart, json, error, resolveStateDir, resolvePath, getHomeDir, isSafeResetStateDir, stateDirExists, removeStateDir, logWarn } = ctx;
|
|
4
|
+
if (method === "POST" && pathname === "/api/agent/restart") {
|
|
5
|
+
if (!onRestart) {
|
|
6
|
+
error(res, "Restart is not supported in this mode (no restart handler registered)", 501);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (state.agentState === "restarting") {
|
|
10
|
+
error(res, "A restart is already in progress", 409);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const previousState = state.agentState;
|
|
14
|
+
state.agentState = "restarting";
|
|
15
|
+
try {
|
|
16
|
+
const newRuntime = await onRestart();
|
|
17
|
+
if (newRuntime) {
|
|
18
|
+
state.runtime = newRuntime;
|
|
19
|
+
state.chatConnectionReady = null;
|
|
20
|
+
state.chatConnectionPromise = null;
|
|
21
|
+
state.agentState = "running";
|
|
22
|
+
state.agentName = newRuntime.character.name ?? "Milady";
|
|
23
|
+
state.startedAt = Date.now();
|
|
24
|
+
state.pendingRestartReasons = [];
|
|
25
|
+
json(res, {
|
|
26
|
+
ok: true,
|
|
27
|
+
pendingRestart: false,
|
|
28
|
+
status: {
|
|
29
|
+
state: state.agentState,
|
|
30
|
+
agentName: state.agentName,
|
|
31
|
+
startedAt: state.startedAt
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
state.agentState = previousState;
|
|
36
|
+
error(res, "Restart handler returned null — runtime failed to re-initialize", 500);
|
|
37
|
+
}
|
|
38
|
+
} catch (err) {
|
|
39
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
40
|
+
state.agentState = previousState;
|
|
41
|
+
error(res, `Restart failed: ${message}`, 500);
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (method === "POST" && pathname === "/api/agent/reset") {
|
|
46
|
+
try {
|
|
47
|
+
if (state.runtime) {
|
|
48
|
+
try {
|
|
49
|
+
await state.runtime.stop();
|
|
50
|
+
} catch (stopErr) {
|
|
51
|
+
logWarn(`[milady-api] Error stopping runtime during reset: ${stopErr instanceof Error ? stopErr.message : String(stopErr)}`);
|
|
52
|
+
}
|
|
53
|
+
state.runtime = null;
|
|
54
|
+
}
|
|
55
|
+
const resolvedState = resolvePath(resolveStateDir());
|
|
56
|
+
if (!isSafeResetStateDir(resolvedState, getHomeDir())) {
|
|
57
|
+
logWarn(`[milady-api] Refusing to delete unsafe state dir: "${resolvedState}"`);
|
|
58
|
+
error(res, `Reset aborted: state directory "${resolvedState}" does not appear safe to delete`, 400);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (stateDirExists(resolvedState)) removeStateDir(resolvedState);
|
|
62
|
+
state.agentState = "stopped";
|
|
63
|
+
state.agentName = "Milady";
|
|
64
|
+
state.model = void 0;
|
|
65
|
+
state.startedAt = void 0;
|
|
66
|
+
state.config = {};
|
|
67
|
+
state.chatRoomId = null;
|
|
68
|
+
state.chatUserId = null;
|
|
69
|
+
state.chatConnectionReady = null;
|
|
70
|
+
state.chatConnectionPromise = null;
|
|
71
|
+
state.pendingRestartReasons = [];
|
|
72
|
+
json(res, { ok: true });
|
|
73
|
+
} catch (err) {
|
|
74
|
+
error(res, `Reset failed: ${err instanceof Error ? err.message : String(err)}`, 500);
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { handleAgentAdminRoutes };
|