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,57 @@
1
+ import { logger } from "@elizaos/core";
2
+
3
+ //#region src/diagnostics/integration-observability.ts
4
+ const EVENT_PREFIX = "[integration]";
5
+ function inferErrorKind(error) {
6
+ if (error instanceof Error) {
7
+ const message = error.message.toLowerCase();
8
+ if (error.name === "AbortError" || error.name === "TimeoutError" || message.includes("timeout") || message.includes("timed out")) return "timeout";
9
+ return sanitizeToken(error.name);
10
+ }
11
+ if (typeof error === "string") return sanitizeToken(error);
12
+ }
13
+ function sanitizeToken(value) {
14
+ if (!value) return void 0;
15
+ const normalized = value.toLowerCase().replace(/[^a-z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
16
+ return normalized ? normalized.slice(0, 64) : void 0;
17
+ }
18
+ function emitEvent(sink, event) {
19
+ const line = `${EVENT_PREFIX} ${JSON.stringify(event)}`;
20
+ if (event.outcome === "success") {
21
+ sink.info(line);
22
+ return;
23
+ }
24
+ sink.warn(line);
25
+ }
26
+ function createIntegrationTelemetrySpan(meta, options = {}) {
27
+ const now = options.now ?? Date.now;
28
+ const sink = options.sink ?? logger;
29
+ const startedAt = now();
30
+ let settled = false;
31
+ const finalize = (outcome, args) => {
32
+ if (settled) return;
33
+ settled = true;
34
+ const durationMs = Math.max(0, now() - startedAt);
35
+ const event = {
36
+ schema: "integration_boundary_v1",
37
+ boundary: meta.boundary,
38
+ operation: meta.operation,
39
+ outcome,
40
+ durationMs
41
+ };
42
+ if (typeof meta.timeoutMs === "number") event.timeoutMs = meta.timeoutMs;
43
+ if (typeof args?.statusCode === "number") event.statusCode = args.statusCode;
44
+ if (outcome === "failure") {
45
+ const failureArgs = args;
46
+ event.errorKind = sanitizeToken(failureArgs?.errorKind) ?? inferErrorKind(failureArgs?.error);
47
+ }
48
+ emitEvent(sink, event);
49
+ };
50
+ return {
51
+ success: (args) => finalize("success", args),
52
+ failure: (args) => finalize("failure", args)
53
+ };
54
+ }
55
+
56
+ //#endregion
57
+ export { createIntegrationTelemetrySpan };
@@ -0,0 +1,205 @@
1
+ import { parseClampedInteger } from "./utils/number-parsing.js";
2
+ import { AUDIT_EVENT_TYPES, AUDIT_SEVERITIES, getAuditFeedSize, queryAuditFeed, subscribeAuditFeed } from "./security/audit-log.js";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ //#region src/api/diagnostics-routes.ts
8
+ async function defaultCheckRelayReachable(relayPort) {
9
+ try {
10
+ const response = await fetch(`http://127.0.0.1:${relayPort}/`, {
11
+ method: "HEAD",
12
+ signal: AbortSignal.timeout(2e3)
13
+ });
14
+ return response.ok || response.status < 500;
15
+ } catch {
16
+ return false;
17
+ }
18
+ }
19
+ function defaultResolveExtensionPath() {
20
+ try {
21
+ const serverDir = path.dirname(fileURLToPath(import.meta.url));
22
+ const extensionPath = path.resolve(serverDir, "..", "..", "apps", "chrome-extension");
23
+ return fs.existsSync(extensionPath) ? extensionPath : null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ function isAutonomyEvent(event) {
29
+ return event.type === "agent_event" || event.type === "heartbeat_event";
30
+ }
31
+ function defaultInitSse(res) {
32
+ res.writeHead(200, {
33
+ "Content-Type": "text/event-stream",
34
+ "Cache-Control": "no-cache",
35
+ Connection: "keep-alive",
36
+ "X-Accel-Buffering": "no"
37
+ });
38
+ }
39
+ function defaultWriteSseData(res, data, event) {
40
+ if (event) res.write(`event: ${event}\n`);
41
+ const safe = data.replace(/\r?\n/g, "\ndata: ");
42
+ res.write(`data: ${safe}\n\n`);
43
+ }
44
+ function defaultWriteSseJson(res, payload, event) {
45
+ defaultWriteSseData(res, JSON.stringify(payload), event);
46
+ }
47
+ function parseAuditSince(raw) {
48
+ if (raw == null) return {};
49
+ const trimmed = raw.trim();
50
+ if (!trimmed) return { error: "Invalid \"since\" filter: expected epoch ms or ISO timestamp." };
51
+ const numeric = Number(trimmed);
52
+ if (Number.isFinite(numeric)) return { value: Math.trunc(numeric) };
53
+ const parsed = Date.parse(trimmed);
54
+ if (!Number.isFinite(parsed)) return { error: "Invalid \"since\" filter: expected epoch ms or ISO timestamp." };
55
+ return { value: parsed };
56
+ }
57
+ function isTruthyQueryParam(value) {
58
+ if (!value) return false;
59
+ const normalized = value.trim().toLowerCase();
60
+ return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
61
+ }
62
+ function matchesAuditFilter(entry, filters) {
63
+ if (filters.type && entry.type !== filters.type) return false;
64
+ if (filters.severity && entry.severity !== filters.severity) return false;
65
+ if (filters.sinceMs !== void 0 && Date.parse(entry.timestamp) < filters.sinceMs) return false;
66
+ return true;
67
+ }
68
+ async function handleDiagnosticsRoutes(ctx) {
69
+ const { req, res, method, pathname, url, logBuffer, eventBuffer, relayPort: relayPortOverride, checkRelayReachable, resolveExtensionPath, initSse, writeSseJson, json } = ctx;
70
+ if (method === "GET" && pathname === "/api/logs") {
71
+ let entries = logBuffer;
72
+ const sourceFilter = url.searchParams.get("source");
73
+ if (sourceFilter) entries = entries.filter((entry) => entry.source === sourceFilter);
74
+ const levelFilter = url.searchParams.get("level");
75
+ if (levelFilter) entries = entries.filter((entry) => entry.level === levelFilter);
76
+ const tagFilter = url.searchParams.get("tag");
77
+ if (tagFilter) entries = entries.filter((entry) => entry.tags.includes(tagFilter));
78
+ const sinceFilter = url.searchParams.get("since");
79
+ if (sinceFilter) {
80
+ const sinceTimestamp = Number(sinceFilter);
81
+ if (!Number.isNaN(sinceTimestamp)) entries = entries.filter((entry) => entry.timestamp >= sinceTimestamp);
82
+ }
83
+ const sources = [...new Set(logBuffer.map((entry) => entry.source))].sort();
84
+ const tags = [...new Set(logBuffer.flatMap((entry) => entry.tags))].sort();
85
+ json(res, {
86
+ entries: entries.slice(-200),
87
+ sources,
88
+ tags
89
+ });
90
+ return true;
91
+ }
92
+ if (method === "GET" && pathname === "/api/agent/events") {
93
+ const limit = parseClampedInteger(url.searchParams.get("limit"), {
94
+ min: 1,
95
+ max: 1e3,
96
+ fallback: 200
97
+ });
98
+ const afterEventId = url.searchParams.get("after");
99
+ const autonomyEvents = eventBuffer.filter(isAutonomyEvent);
100
+ let startIndex = 0;
101
+ if (afterEventId) {
102
+ const index = autonomyEvents.findIndex((event) => event.eventId === afterEventId);
103
+ if (index >= 0) startIndex = index + 1;
104
+ }
105
+ const events = autonomyEvents.slice(startIndex, startIndex + limit);
106
+ json(res, {
107
+ events,
108
+ latestEventId: events.length > 0 ? events[events.length - 1].eventId : null,
109
+ totalBuffered: autonomyEvents.length,
110
+ replayed: true
111
+ });
112
+ return true;
113
+ }
114
+ if (method === "GET" && pathname === "/api/security/audit") {
115
+ const typeFilterRaw = url.searchParams.get("type");
116
+ const severityFilterRaw = url.searchParams.get("severity");
117
+ const limitFilter = parseClampedInteger(url.searchParams.get("limit"), {
118
+ min: 1,
119
+ max: 1e3,
120
+ fallback: 200
121
+ });
122
+ const sinceFilter = parseAuditSince(url.searchParams.get("since"));
123
+ if (sinceFilter.error) {
124
+ json(res, { error: sinceFilter.error }, 400);
125
+ return true;
126
+ }
127
+ let typeFilter;
128
+ if (typeFilterRaw) {
129
+ const candidate = typeFilterRaw.trim();
130
+ if (!AUDIT_EVENT_TYPES.includes(candidate)) {
131
+ json(res, { error: `Invalid "type" filter. Expected one of: ${AUDIT_EVENT_TYPES.join(", ")}` }, 400);
132
+ return true;
133
+ }
134
+ typeFilter = candidate;
135
+ }
136
+ let severityFilter;
137
+ if (severityFilterRaw) {
138
+ const candidate = severityFilterRaw.trim();
139
+ if (!AUDIT_SEVERITIES.includes(candidate)) {
140
+ json(res, { error: `Invalid "severity" filter. Expected one of: ${AUDIT_SEVERITIES.join(", ")}` }, 400);
141
+ return true;
142
+ }
143
+ severityFilter = candidate;
144
+ }
145
+ const streamRequested = isTruthyQueryParam(url.searchParams.get("stream")) || (req.headers.accept ?? "").includes("text/event-stream");
146
+ const filter = {
147
+ type: typeFilter,
148
+ severity: severityFilter,
149
+ sinceMs: sinceFilter.value
150
+ };
151
+ if (!streamRequested) {
152
+ json(res, {
153
+ entries: queryAuditFeed({
154
+ ...filter,
155
+ limit: limitFilter
156
+ }),
157
+ totalBuffered: getAuditFeedSize(),
158
+ replayed: true
159
+ });
160
+ return true;
161
+ }
162
+ const startSse = initSse ?? defaultInitSse;
163
+ const sendSseJson = writeSseJson ?? defaultWriteSseJson;
164
+ startSse(res);
165
+ sendSseJson(res, {
166
+ type: "snapshot",
167
+ entries: queryAuditFeed({
168
+ ...filter,
169
+ limit: limitFilter
170
+ }),
171
+ totalBuffered: getAuditFeedSize()
172
+ });
173
+ const unsubscribe = subscribeAuditFeed((entry) => {
174
+ if (!matchesAuditFilter(entry, filter)) return;
175
+ sendSseJson(res, {
176
+ type: "entry",
177
+ entry
178
+ });
179
+ });
180
+ let closed = false;
181
+ const close = () => {
182
+ if (closed) return;
183
+ closed = true;
184
+ unsubscribe();
185
+ if (!res.writableEnded) res.end();
186
+ };
187
+ req.on("close", close);
188
+ req.on("aborted", close);
189
+ res.on("close", close);
190
+ return true;
191
+ }
192
+ if (method === "GET" && pathname === "/api/extension/status") {
193
+ const relayPort = relayPortOverride ?? 18792;
194
+ json(res, {
195
+ relayReachable: await (checkRelayReachable ?? defaultCheckRelayReachable)(relayPort),
196
+ relayPort,
197
+ extensionPath: (resolveExtensionPath ?? defaultResolveExtensionPath)()
198
+ });
199
+ return true;
200
+ }
201
+ return false;
202
+ }
203
+
204
+ //#endregion
205
+ export { handleDiagnosticsRoutes };
@@ -0,0 +1,134 @@
1
+ import { logger } from "@elizaos/core";
2
+ import { ethers } from "ethers";
3
+
4
+ //#region src/api/drop-service.ts
5
+ /**
6
+ * MiladyMaker drop/mint service.
7
+ *
8
+ * Handles the ERC-8041 fixed-supply collection minting:
9
+ * - Public free mint (user pays gas)
10
+ * - Shiny mint (0.1 ETH + gas)
11
+ * - Whitelist mint (Merkle proof)
12
+ * - Supply tracking and status
13
+ */
14
+ const COLLECTION_ABI = [
15
+ "function mint(string,string,bytes32) external returns (uint256)",
16
+ "function mintShiny(string,string,bytes32) external payable returns (uint256)",
17
+ "function mintWhitelist(string,string,bytes32,bytes32[]) external returns (uint256)",
18
+ "function mintFor(address,string,string,bytes32,bool) external returns (uint256)",
19
+ "function currentSupply() view returns (uint256)",
20
+ "function publicMintOpen() view returns (bool)",
21
+ "function whitelistMintOpen() view returns (bool)",
22
+ "function hasMinted(address) view returns (bool)",
23
+ "function getAgentMintNumber(uint256) view returns (uint256)",
24
+ "function isShiny(uint256) view returns (bool)",
25
+ "function getCollectionDetails() view returns (uint256,uint256,bool)",
26
+ "function MAX_SUPPLY() view returns (uint256)",
27
+ "function SHINY_PRICE() view returns (uint256)",
28
+ "function merkleRoot() view returns (bytes32)",
29
+ "event AgentMinted(uint256 indexed agentId, uint256 indexed mintNumber, address indexed owner, bool shiny)",
30
+ "event CollectionUpdated(uint256 maxSupply, uint256 currentSupply, bool publicOpen, bool whitelistOpen)"
31
+ ];
32
+ const DEFAULT_CAP_HASH = ethers.id("milady-agent");
33
+ var DropService = class {
34
+ constructor(txService, collectionAddress, dropEnabled) {
35
+ this.txService = txService;
36
+ this.contract = txService.getContract(collectionAddress, COLLECTION_ABI);
37
+ this.dropEnabled = dropEnabled;
38
+ }
39
+ async getStatus() {
40
+ if (!this.dropEnabled) return {
41
+ dropEnabled: false,
42
+ publicMintOpen: false,
43
+ whitelistMintOpen: false,
44
+ mintedOut: false,
45
+ currentSupply: 0,
46
+ maxSupply: 2138,
47
+ shinyPrice: "0.1",
48
+ userHasMinted: false
49
+ };
50
+ const [collectionDetails, whitelistOpen, hasMinted, shinyPriceBN] = await Promise.all([
51
+ this.contract.getCollectionDetails(),
52
+ this.contract.whitelistMintOpen(),
53
+ this.contract.hasMinted(this.txService.address),
54
+ this.contract.SHINY_PRICE()
55
+ ]);
56
+ const [maxSupply, currentSupply, publicOpen] = collectionDetails;
57
+ const maxSupplyNum = Number(maxSupply);
58
+ const currentSupplyNum = Number(currentSupply);
59
+ return {
60
+ dropEnabled: true,
61
+ publicMintOpen: publicOpen,
62
+ whitelistMintOpen: whitelistOpen,
63
+ mintedOut: currentSupplyNum >= maxSupplyNum,
64
+ currentSupply: currentSupplyNum,
65
+ maxSupply: maxSupplyNum,
66
+ shinyPrice: ethers.formatEther(shinyPriceBN),
67
+ userHasMinted: hasMinted
68
+ };
69
+ }
70
+ async mint(name, endpoint, capabilitiesHash) {
71
+ const capHash = capabilitiesHash || DEFAULT_CAP_HASH;
72
+ logger.info(`[drop] Minting agent "${name}" for ${this.txService.address}`);
73
+ const nonce = await this.txService.getFreshNonce();
74
+ const tx = await this.contract.mint(name, endpoint, capHash, { nonce });
75
+ logger.info(`[drop] Mint tx submitted: ${tx.hash}`);
76
+ const receipt = await tx.wait();
77
+ return this.parseMintReceipt(receipt, false);
78
+ }
79
+ async mintShiny(name, endpoint, capabilitiesHash) {
80
+ const capHash = capabilitiesHash || DEFAULT_CAP_HASH;
81
+ const shinyPrice = await this.contract.SHINY_PRICE();
82
+ logger.info(`[drop] Minting SHINY agent "${name}" for ${this.txService.address} (${ethers.formatEther(shinyPrice)} ETH)`);
83
+ const nonce = await this.txService.getFreshNonce();
84
+ const tx = await this.contract.mintShiny(name, endpoint, capHash, {
85
+ value: shinyPrice,
86
+ nonce
87
+ });
88
+ logger.info(`[drop] Shiny mint tx submitted: ${tx.hash}`);
89
+ const receipt = await tx.wait();
90
+ return this.parseMintReceipt(receipt, true);
91
+ }
92
+ async mintWithWhitelist(name, endpoint, proof, capabilitiesHash) {
93
+ const capHash = capabilitiesHash || DEFAULT_CAP_HASH;
94
+ logger.info(`[drop] Whitelist minting agent "${name}" for ${this.txService.address}`);
95
+ const nonce = await this.txService.getFreshNonce();
96
+ const tx = await this.contract.mintWhitelist(name, endpoint, capHash, proof, { nonce });
97
+ logger.info(`[drop] Whitelist mint tx submitted: ${tx.hash}`);
98
+ const receipt = await tx.wait();
99
+ return this.parseMintReceipt(receipt, false);
100
+ }
101
+ async getMintNumber(agentId) {
102
+ return Number(await this.contract.getAgentMintNumber(agentId));
103
+ }
104
+ async checkIsShiny(agentId) {
105
+ return this.contract.isShiny(agentId);
106
+ }
107
+ parseMintReceipt(receipt, shiny) {
108
+ const iface = new ethers.Interface(COLLECTION_ABI);
109
+ let agentId = 0;
110
+ let mintNumber = 0;
111
+ for (const log of receipt.logs) {
112
+ const parsed = iface.parseLog({
113
+ topics: log.topics,
114
+ data: log.data
115
+ });
116
+ if (parsed && parsed.name === "AgentMinted") {
117
+ agentId = Number(parsed.args[0]);
118
+ mintNumber = Number(parsed.args[1]);
119
+ shiny = parsed.args[3];
120
+ break;
121
+ }
122
+ }
123
+ logger.info(`[drop] Minted: agentId=${agentId} mintNumber=${mintNumber} shiny=${shiny} txHash=${receipt.hash}`);
124
+ return {
125
+ agentId,
126
+ mintNumber,
127
+ txHash: receipt.hash,
128
+ isShiny: shiny
129
+ };
130
+ }
131
+ };
132
+
133
+ //#endregion
134
+ export { DropService };
@@ -0,0 +1,24 @@
1
+ import { logger } from "@elizaos/core";
2
+
3
+ //#region src/api/early-logs.ts
4
+ let earlyLogBuffer = null;
5
+ let earlyPatchCleanup = null;
6
+ /**
7
+ * Drain the early log buffer and clean up the early logger patch.
8
+ * Called by `startApiServer` to flush buffered entries into the main log
9
+ * buffer, then hand control to the server's own logger patch.
10
+ *
11
+ * Returns the buffered entries (empty array if none).
12
+ */
13
+ function flushEarlyLogs() {
14
+ const entries = earlyLogBuffer ? [...earlyLogBuffer] : [];
15
+ if (earlyPatchCleanup) {
16
+ earlyPatchCleanup();
17
+ earlyPatchCleanup = null;
18
+ }
19
+ earlyLogBuffer = null;
20
+ return entries;
21
+ }
22
+
23
+ //#endregion
24
+ export { flushEarlyLogs };