@elizaos/server 1.5.8-alpha.20 → 1.5.8-alpha.22
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/api/agents/index.d.ts.map +1 -1
- package/dist/api/agents/runs.d.ts +7 -0
- package/dist/api/agents/runs.d.ts.map +1 -0
- package/dist/index.js +448 -169
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -732,7 +732,7 @@ import {
|
|
|
732
732
|
parseBooleanFromText
|
|
733
733
|
} from "@elizaos/core";
|
|
734
734
|
import cors2 from "cors";
|
|
735
|
-
import
|
|
735
|
+
import express33 from "express";
|
|
736
736
|
|
|
737
737
|
// ../../node_modules/helmet/index.mjs
|
|
738
738
|
var dangerouslyDisableDefaultSrc = Symbol("dangerouslyDisableDefaultSrc");
|
|
@@ -1281,14 +1281,14 @@ import path6, { basename, dirname, extname, join } from "node:path";
|
|
|
1281
1281
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1282
1282
|
|
|
1283
1283
|
// src/api/index.ts
|
|
1284
|
-
import { logger as logger26, validateUuid as
|
|
1284
|
+
import { logger as logger26, validateUuid as validateUuid23 } from "@elizaos/core";
|
|
1285
1285
|
import cors from "cors";
|
|
1286
|
-
import
|
|
1286
|
+
import express32 from "express";
|
|
1287
1287
|
var import_path_to_regexp = __toESM(require_dist(), 1);
|
|
1288
1288
|
import { Server as SocketIOServer } from "socket.io";
|
|
1289
1289
|
|
|
1290
1290
|
// src/api/agents/index.ts
|
|
1291
|
-
import
|
|
1291
|
+
import express9 from "express";
|
|
1292
1292
|
|
|
1293
1293
|
// src/api/agents/crud.ts
|
|
1294
1294
|
import {
|
|
@@ -1816,15 +1816,293 @@ function createAgentLogsRouter(agents) {
|
|
|
1816
1816
|
return router;
|
|
1817
1817
|
}
|
|
1818
1818
|
|
|
1819
|
+
// src/api/agents/runs.ts
|
|
1820
|
+
import { validateUuid as validateUuid6 } from "@elizaos/core";
|
|
1821
|
+
import express6 from "express";
|
|
1822
|
+
function createAgentRunsRouter(agents) {
|
|
1823
|
+
const router = express6.Router();
|
|
1824
|
+
router.get("/:agentId/runs", async (req, res) => {
|
|
1825
|
+
const agentId = validateUuid6(req.params.agentId);
|
|
1826
|
+
if (!agentId) {
|
|
1827
|
+
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
1828
|
+
}
|
|
1829
|
+
const runtime = agents.get(agentId);
|
|
1830
|
+
if (!runtime) {
|
|
1831
|
+
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
1832
|
+
}
|
|
1833
|
+
const { roomId, status, limit = 20, from, to } = req.query;
|
|
1834
|
+
if (roomId && !validateUuid6(roomId)) {
|
|
1835
|
+
return sendError(res, 400, "INVALID_ID", "Invalid room ID format");
|
|
1836
|
+
}
|
|
1837
|
+
try {
|
|
1838
|
+
const limitNum = Math.min(Number(limit) || 20, 100);
|
|
1839
|
+
const fromTime = from ? Number(from) : undefined;
|
|
1840
|
+
const toTime = to ? Number(to) : undefined;
|
|
1841
|
+
const runEventLogs = await runtime.getLogs({
|
|
1842
|
+
entityId: agentId,
|
|
1843
|
+
roomId: roomId ? roomId : undefined,
|
|
1844
|
+
type: "run_event",
|
|
1845
|
+
count: limitNum * 3
|
|
1846
|
+
});
|
|
1847
|
+
const runMap = new Map;
|
|
1848
|
+
for (const log of runEventLogs) {
|
|
1849
|
+
const body = log.body;
|
|
1850
|
+
const runId = body.runId;
|
|
1851
|
+
if (!runId)
|
|
1852
|
+
continue;
|
|
1853
|
+
const logTime = new Date(log.createdAt).getTime();
|
|
1854
|
+
if (fromTime && logTime < fromTime)
|
|
1855
|
+
continue;
|
|
1856
|
+
if (toTime && logTime > toTime)
|
|
1857
|
+
continue;
|
|
1858
|
+
if (!runMap.has(runId)) {
|
|
1859
|
+
runMap.set(runId, {
|
|
1860
|
+
runId,
|
|
1861
|
+
status: "started",
|
|
1862
|
+
startedAt: null,
|
|
1863
|
+
endedAt: null,
|
|
1864
|
+
durationMs: null,
|
|
1865
|
+
messageId: body.messageId,
|
|
1866
|
+
roomId: body.roomId,
|
|
1867
|
+
entityId: body.entityId,
|
|
1868
|
+
metadata: body.metadata || {}
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
const run = runMap.get(runId);
|
|
1872
|
+
const eventStatus = body.status;
|
|
1873
|
+
if (eventStatus === "started") {
|
|
1874
|
+
run.startedAt = logTime;
|
|
1875
|
+
} else if (eventStatus === "completed" || eventStatus === "timeout" || eventStatus === "error") {
|
|
1876
|
+
run.status = eventStatus;
|
|
1877
|
+
run.endedAt = logTime;
|
|
1878
|
+
if (run.startedAt) {
|
|
1879
|
+
run.durationMs = logTime - run.startedAt;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
let runs = Array.from(runMap.values());
|
|
1884
|
+
if (status && status !== "all") {
|
|
1885
|
+
runs = runs.filter((run) => run.status === status);
|
|
1886
|
+
}
|
|
1887
|
+
runs.sort((a, b) => (b.startedAt || 0) - (a.startedAt || 0));
|
|
1888
|
+
const limitedRuns = runs.slice(0, limitNum);
|
|
1889
|
+
const runIdSet = new Set(limitedRuns.map((r) => r.runId));
|
|
1890
|
+
const [actionLogs, evaluatorLogs, genericLogs] = await Promise.all([
|
|
1891
|
+
runtime.getLogs({
|
|
1892
|
+
entityId: agentId,
|
|
1893
|
+
roomId: roomId ? roomId : undefined,
|
|
1894
|
+
type: "action",
|
|
1895
|
+
count: 5000
|
|
1896
|
+
}),
|
|
1897
|
+
runtime.getLogs({
|
|
1898
|
+
entityId: agentId,
|
|
1899
|
+
roomId: roomId ? roomId : undefined,
|
|
1900
|
+
type: "evaluator",
|
|
1901
|
+
count: 5000
|
|
1902
|
+
}),
|
|
1903
|
+
runtime.getLogs({
|
|
1904
|
+
entityId: agentId,
|
|
1905
|
+
roomId: roomId ? roomId : undefined,
|
|
1906
|
+
count: 5000
|
|
1907
|
+
})
|
|
1908
|
+
]);
|
|
1909
|
+
const countsByRunId = {};
|
|
1910
|
+
for (const run of limitedRuns) {
|
|
1911
|
+
countsByRunId[run.runId] = { actions: 0, modelCalls: 0, errors: 0, evaluators: 0 };
|
|
1912
|
+
}
|
|
1913
|
+
for (const log of actionLogs) {
|
|
1914
|
+
const rid = log.body.runId;
|
|
1915
|
+
if (!rid || !runIdSet.has(rid))
|
|
1916
|
+
continue;
|
|
1917
|
+
const entry = countsByRunId[rid];
|
|
1918
|
+
if (!entry)
|
|
1919
|
+
continue;
|
|
1920
|
+
entry.actions += 1;
|
|
1921
|
+
const bodyForAction = log.body;
|
|
1922
|
+
if (bodyForAction.result?.success === false)
|
|
1923
|
+
entry.errors += 1;
|
|
1924
|
+
const promptCount = Number(bodyForAction.promptCount || 0);
|
|
1925
|
+
if (promptCount > 0)
|
|
1926
|
+
entry.modelCalls += promptCount;
|
|
1927
|
+
}
|
|
1928
|
+
for (const log of evaluatorLogs) {
|
|
1929
|
+
const rid = log.body.runId;
|
|
1930
|
+
if (!rid || !runIdSet.has(rid))
|
|
1931
|
+
continue;
|
|
1932
|
+
const entry = countsByRunId[rid];
|
|
1933
|
+
if (!entry)
|
|
1934
|
+
continue;
|
|
1935
|
+
entry.evaluators += 1;
|
|
1936
|
+
}
|
|
1937
|
+
for (const log of genericLogs) {
|
|
1938
|
+
const rid = log.body.runId;
|
|
1939
|
+
if (!rid || !runIdSet.has(rid))
|
|
1940
|
+
continue;
|
|
1941
|
+
const entry = countsByRunId[rid];
|
|
1942
|
+
if (!entry)
|
|
1943
|
+
continue;
|
|
1944
|
+
if (typeof log.type === "string" && log.type.startsWith("useModel:")) {
|
|
1945
|
+
entry.modelCalls += 1;
|
|
1946
|
+
} else if (log.type === "embedding_event" && log.body.status === "failed") {
|
|
1947
|
+
entry.errors += 1;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
for (const run of limitedRuns) {
|
|
1951
|
+
run.counts = countsByRunId[run.runId] || { actions: 0, modelCalls: 0, errors: 0, evaluators: 0 };
|
|
1952
|
+
}
|
|
1953
|
+
const response = {
|
|
1954
|
+
runs: limitedRuns,
|
|
1955
|
+
total: runs.length,
|
|
1956
|
+
hasMore: runs.length > limitNum
|
|
1957
|
+
};
|
|
1958
|
+
sendSuccess(res, response);
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
sendError(res, 500, "RUNS_ERROR", "Error retrieving agent runs", error instanceof Error ? error.message : String(error));
|
|
1961
|
+
}
|
|
1962
|
+
});
|
|
1963
|
+
router.get("/:agentId/runs/:runId", async (req, res) => {
|
|
1964
|
+
const agentId = validateUuid6(req.params.agentId);
|
|
1965
|
+
const runId = validateUuid6(req.params.runId);
|
|
1966
|
+
const { roomId } = req.query;
|
|
1967
|
+
if (!agentId || !runId) {
|
|
1968
|
+
return sendError(res, 400, "INVALID_ID", "Invalid agent or run ID format");
|
|
1969
|
+
}
|
|
1970
|
+
if (roomId && !validateUuid6(roomId)) {
|
|
1971
|
+
return sendError(res, 400, "INVALID_ID", "Invalid room ID format");
|
|
1972
|
+
}
|
|
1973
|
+
const runtime = agents.get(agentId);
|
|
1974
|
+
if (!runtime) {
|
|
1975
|
+
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
1976
|
+
}
|
|
1977
|
+
try {
|
|
1978
|
+
const logs = await runtime.getLogs({
|
|
1979
|
+
entityId: agentId,
|
|
1980
|
+
roomId: roomId ? roomId : undefined,
|
|
1981
|
+
count: 2000
|
|
1982
|
+
});
|
|
1983
|
+
const related = logs.filter((l) => l.body.runId === runId);
|
|
1984
|
+
const runEvents = related.filter((l) => l.type === "run_event").sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
1985
|
+
const started = runEvents.find((e) => e.body.status === "started");
|
|
1986
|
+
const last = runEvents[runEvents.length - 1];
|
|
1987
|
+
const startedAt = started ? new Date(started.createdAt).getTime() : undefined;
|
|
1988
|
+
const endedAt = last && last.body.status !== "started" ? new Date(last.createdAt).getTime() : undefined;
|
|
1989
|
+
const status = last?.body?.status || "started";
|
|
1990
|
+
const durationMs = startedAt && endedAt ? endedAt - startedAt : undefined;
|
|
1991
|
+
const actionLogs = related.filter((l) => l.type === "action");
|
|
1992
|
+
const actionEventLogs = related.filter((l) => l.type === "action_event");
|
|
1993
|
+
const evaluatorLogs = related.filter((l) => l.type === "evaluator");
|
|
1994
|
+
const embeddingLogs = related.filter((l) => l.type === "embedding_event");
|
|
1995
|
+
const modelLogs = related.filter((l) => typeof l.type === "string" && l.type.startsWith("useModel:"));
|
|
1996
|
+
const counts = {
|
|
1997
|
+
actions: actionEventLogs.length || actionLogs.length,
|
|
1998
|
+
modelCalls: (actionLogs.reduce((sum, l) => sum + Number(l.body.promptCount || 0), 0) || 0) + modelLogs.length,
|
|
1999
|
+
errors: actionLogs.filter((l) => l.body.result?.success === false).length + embeddingLogs.filter((l) => l.body.status === "failed").length,
|
|
2000
|
+
evaluators: evaluatorLogs.length
|
|
2001
|
+
};
|
|
2002
|
+
const events = [];
|
|
2003
|
+
for (const e of runEvents) {
|
|
2004
|
+
const t = new Date(e.createdAt).getTime();
|
|
2005
|
+
const body = e.body;
|
|
2006
|
+
const st = body.status;
|
|
2007
|
+
if (st === "started") {
|
|
2008
|
+
events.push({ type: "RUN_STARTED", timestamp: t, data: { source: body.source ?? undefined, messageId: body.messageId } });
|
|
2009
|
+
} else {
|
|
2010
|
+
events.push({ type: "RUN_ENDED", timestamp: t, data: { status: st, error: body.error, durationMs: body.duration } });
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
for (const e of actionEventLogs) {
|
|
2014
|
+
const body = e.body;
|
|
2015
|
+
events.push({
|
|
2016
|
+
type: "ACTION_STARTED",
|
|
2017
|
+
timestamp: new Date(e.createdAt).getTime(),
|
|
2018
|
+
data: {
|
|
2019
|
+
actionId: body.actionId,
|
|
2020
|
+
actionName: body.actionName || body.content?.actions?.[0],
|
|
2021
|
+
messageId: body.messageId,
|
|
2022
|
+
planStep: body.planStep
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
for (const e of actionLogs) {
|
|
2027
|
+
const body = e.body;
|
|
2028
|
+
events.push({
|
|
2029
|
+
type: "ACTION_COMPLETED",
|
|
2030
|
+
timestamp: new Date(e.createdAt).getTime(),
|
|
2031
|
+
data: {
|
|
2032
|
+
actionId: body.actionId,
|
|
2033
|
+
actionName: body.action,
|
|
2034
|
+
success: body.result?.success !== false,
|
|
2035
|
+
result: body.result,
|
|
2036
|
+
promptCount: body.promptCount
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
for (const e of modelLogs) {
|
|
2041
|
+
const body = e.body;
|
|
2042
|
+
events.push({
|
|
2043
|
+
type: "MODEL_USED",
|
|
2044
|
+
timestamp: new Date(e.createdAt).getTime(),
|
|
2045
|
+
data: {
|
|
2046
|
+
modelType: body.modelType || (typeof e.type === "string" ? e.type.replace("useModel:", "") : undefined),
|
|
2047
|
+
provider: body.provider,
|
|
2048
|
+
executionTime: body.executionTime,
|
|
2049
|
+
actionContext: body.actionContext
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
for (const e of evaluatorLogs) {
|
|
2054
|
+
const body = e.body;
|
|
2055
|
+
events.push({
|
|
2056
|
+
type: "EVALUATOR_COMPLETED",
|
|
2057
|
+
timestamp: new Date(e.createdAt).getTime(),
|
|
2058
|
+
data: {
|
|
2059
|
+
evaluatorName: body.evaluator,
|
|
2060
|
+
success: true
|
|
2061
|
+
}
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
for (const e of embeddingLogs) {
|
|
2065
|
+
const body = e.body;
|
|
2066
|
+
events.push({
|
|
2067
|
+
type: "EMBEDDING_EVENT",
|
|
2068
|
+
timestamp: new Date(e.createdAt).getTime(),
|
|
2069
|
+
data: {
|
|
2070
|
+
status: body.status,
|
|
2071
|
+
memoryId: body.memoryId,
|
|
2072
|
+
durationMs: body.duration
|
|
2073
|
+
}
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
events.sort((a, b) => a.timestamp - b.timestamp);
|
|
2077
|
+
const firstRunEvent = started || runEvents[0] || related[0];
|
|
2078
|
+
const summary = {
|
|
2079
|
+
runId,
|
|
2080
|
+
status,
|
|
2081
|
+
startedAt: startedAt || (firstRunEvent ? new Date(firstRunEvent.createdAt).getTime() : undefined),
|
|
2082
|
+
endedAt,
|
|
2083
|
+
durationMs,
|
|
2084
|
+
messageId: firstRunEvent?.body?.messageId,
|
|
2085
|
+
roomId: firstRunEvent?.body?.roomId || roomId,
|
|
2086
|
+
entityId: firstRunEvent?.body?.entityId || agentId,
|
|
2087
|
+
counts
|
|
2088
|
+
};
|
|
2089
|
+
sendSuccess(res, { summary, events });
|
|
2090
|
+
} catch (error) {
|
|
2091
|
+
sendError(res, 500, "RUN_DETAIL_ERROR", "Error retrieving run details", error instanceof Error ? error.message : String(error));
|
|
2092
|
+
}
|
|
2093
|
+
});
|
|
2094
|
+
return router;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
1819
2097
|
// src/api/memory/agents.ts
|
|
1820
2098
|
import { MemoryType, createUniqueUuid as createUniqueUuid2 } from "@elizaos/core";
|
|
1821
|
-
import { validateUuid as
|
|
1822
|
-
import
|
|
2099
|
+
import { validateUuid as validateUuid7, logger as logger6 } from "@elizaos/core";
|
|
2100
|
+
import express7 from "express";
|
|
1823
2101
|
function createAgentMemoryRouter(agents) {
|
|
1824
|
-
const router =
|
|
2102
|
+
const router = express7.Router();
|
|
1825
2103
|
router.get("/:agentId/rooms/:roomId/memories", async (req, res) => {
|
|
1826
|
-
const agentId =
|
|
1827
|
-
const roomId =
|
|
2104
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
2105
|
+
const roomId = validateUuid7(req.params.roomId);
|
|
1828
2106
|
if (!agentId || !roomId) {
|
|
1829
2107
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or room ID format");
|
|
1830
2108
|
}
|
|
@@ -1854,7 +2132,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
1854
2132
|
}
|
|
1855
2133
|
});
|
|
1856
2134
|
router.get("/:agentId/memories", async (req, res) => {
|
|
1857
|
-
const agentId =
|
|
2135
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
1858
2136
|
if (!agentId) {
|
|
1859
2137
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID");
|
|
1860
2138
|
}
|
|
@@ -1867,14 +2145,14 @@ function createAgentMemoryRouter(agents) {
|
|
|
1867
2145
|
const includeEmbedding = req.query.includeEmbedding === "true";
|
|
1868
2146
|
let roomIdToUse;
|
|
1869
2147
|
if (req.query.channelId) {
|
|
1870
|
-
const channelId =
|
|
2148
|
+
const channelId = validateUuid7(req.query.channelId);
|
|
1871
2149
|
if (!channelId) {
|
|
1872
2150
|
return sendError(res, 400, "INVALID_ID", "Invalid channel ID format");
|
|
1873
2151
|
}
|
|
1874
2152
|
roomIdToUse = createUniqueUuid2(runtime, channelId);
|
|
1875
2153
|
logger6.info(`[AGENT MEMORIES] Converting channelId ${channelId} to roomId ${roomIdToUse} for agent ${agentId}`);
|
|
1876
2154
|
} else if (req.query.roomId) {
|
|
1877
|
-
const roomId =
|
|
2155
|
+
const roomId = validateUuid7(req.query.roomId);
|
|
1878
2156
|
if (!roomId) {
|
|
1879
2157
|
return sendError(res, 400, "INVALID_ID", "Invalid room ID format");
|
|
1880
2158
|
}
|
|
@@ -1896,8 +2174,8 @@ function createAgentMemoryRouter(agents) {
|
|
|
1896
2174
|
}
|
|
1897
2175
|
});
|
|
1898
2176
|
router.patch("/:agentId/memories/:memoryId", async (req, res) => {
|
|
1899
|
-
const agentId =
|
|
1900
|
-
const memoryId =
|
|
2177
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
2178
|
+
const memoryId = validateUuid7(req.params.memoryId);
|
|
1901
2179
|
const { id: _idFromData, ...restOfMemoryData } = req.body;
|
|
1902
2180
|
if (!agentId || !memoryId) {
|
|
1903
2181
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or memory ID format");
|
|
@@ -1910,10 +2188,10 @@ function createAgentMemoryRouter(agents) {
|
|
|
1910
2188
|
const memoryToUpdate = {
|
|
1911
2189
|
id: memoryId,
|
|
1912
2190
|
...restOfMemoryData,
|
|
1913
|
-
agentId: restOfMemoryData.agentId ?
|
|
1914
|
-
roomId: restOfMemoryData.roomId ?
|
|
1915
|
-
entityId: restOfMemoryData.entityId ?
|
|
1916
|
-
worldId: restOfMemoryData.worldId ?
|
|
2191
|
+
agentId: restOfMemoryData.agentId ? validateUuid7(restOfMemoryData.agentId) || undefined : agentId,
|
|
2192
|
+
roomId: restOfMemoryData.roomId ? validateUuid7(restOfMemoryData.roomId) || undefined : undefined,
|
|
2193
|
+
entityId: restOfMemoryData.entityId ? validateUuid7(restOfMemoryData.entityId) || undefined : undefined,
|
|
2194
|
+
worldId: restOfMemoryData.worldId ? validateUuid7(restOfMemoryData.worldId) || undefined : undefined,
|
|
1917
2195
|
metadata: restOfMemoryData.metadata
|
|
1918
2196
|
};
|
|
1919
2197
|
Object.keys(memoryToUpdate).forEach((key) => {
|
|
@@ -1931,7 +2209,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
1931
2209
|
});
|
|
1932
2210
|
router.delete("/:agentId/memories", async (req, res) => {
|
|
1933
2211
|
try {
|
|
1934
|
-
const agentId =
|
|
2212
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
1935
2213
|
if (!agentId) {
|
|
1936
2214
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID");
|
|
1937
2215
|
}
|
|
@@ -1949,8 +2227,8 @@ function createAgentMemoryRouter(agents) {
|
|
|
1949
2227
|
});
|
|
1950
2228
|
router.delete("/:agentId/memories/all/:roomId", async (req, res) => {
|
|
1951
2229
|
try {
|
|
1952
|
-
const agentId =
|
|
1953
|
-
const roomId =
|
|
2230
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
2231
|
+
const roomId = validateUuid7(req.params.roomId);
|
|
1954
2232
|
if (!agentId) {
|
|
1955
2233
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID");
|
|
1956
2234
|
}
|
|
@@ -1971,8 +2249,8 @@ function createAgentMemoryRouter(agents) {
|
|
|
1971
2249
|
});
|
|
1972
2250
|
router.delete("/:agentId/memories/:memoryId", async (req, res) => {
|
|
1973
2251
|
try {
|
|
1974
|
-
const agentId =
|
|
1975
|
-
const memoryId =
|
|
2252
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
2253
|
+
const memoryId = validateUuid7(req.params.memoryId);
|
|
1976
2254
|
if (!agentId || !memoryId) {
|
|
1977
2255
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or memory ID format");
|
|
1978
2256
|
}
|
|
@@ -1991,12 +2269,12 @@ function createAgentMemoryRouter(agents) {
|
|
|
1991
2269
|
}
|
|
1992
2270
|
|
|
1993
2271
|
// src/api/memory/rooms.ts
|
|
1994
|
-
import { validateUuid as
|
|
1995
|
-
import
|
|
2272
|
+
import { validateUuid as validateUuid8, logger as logger7, createUniqueUuid as createUniqueUuid3, ChannelType } from "@elizaos/core";
|
|
2273
|
+
import express8 from "express";
|
|
1996
2274
|
function createRoomManagementRouter(agents) {
|
|
1997
|
-
const router =
|
|
2275
|
+
const router = express8.Router();
|
|
1998
2276
|
router.post("/:agentId/rooms", async (req, res) => {
|
|
1999
|
-
const agentId =
|
|
2277
|
+
const agentId = validateUuid8(req.params.agentId);
|
|
2000
2278
|
if (!agentId) {
|
|
2001
2279
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
2002
2280
|
}
|
|
@@ -2053,7 +2331,7 @@ function createRoomManagementRouter(agents) {
|
|
|
2053
2331
|
}
|
|
2054
2332
|
});
|
|
2055
2333
|
router.get("/:agentId/rooms", async (req, res) => {
|
|
2056
|
-
const agentId =
|
|
2334
|
+
const agentId = validateUuid8(req.params.agentId);
|
|
2057
2335
|
if (!agentId) {
|
|
2058
2336
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
2059
2337
|
}
|
|
@@ -2082,8 +2360,8 @@ function createRoomManagementRouter(agents) {
|
|
|
2082
2360
|
}
|
|
2083
2361
|
});
|
|
2084
2362
|
router.get("/:agentId/rooms/:roomId", async (req, res) => {
|
|
2085
|
-
const agentId =
|
|
2086
|
-
const roomId =
|
|
2363
|
+
const agentId = validateUuid8(req.params.agentId);
|
|
2364
|
+
const roomId = validateUuid8(req.params.roomId);
|
|
2087
2365
|
if (!agentId || !roomId) {
|
|
2088
2366
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or room ID format");
|
|
2089
2367
|
}
|
|
@@ -2115,23 +2393,24 @@ function createRoomManagementRouter(agents) {
|
|
|
2115
2393
|
|
|
2116
2394
|
// src/api/agents/index.ts
|
|
2117
2395
|
function agentsRouter(agents, serverInstance) {
|
|
2118
|
-
const router =
|
|
2396
|
+
const router = express9.Router();
|
|
2119
2397
|
router.use("/", createAgentCrudRouter(agents, serverInstance));
|
|
2120
2398
|
router.use("/", createAgentLifecycleRouter(agents, serverInstance));
|
|
2121
2399
|
router.use("/", createAgentWorldsRouter(agents));
|
|
2122
2400
|
router.use("/", createAgentPanelsRouter(agents));
|
|
2123
2401
|
router.use("/", createAgentLogsRouter(agents));
|
|
2402
|
+
router.use("/", createAgentRunsRouter(agents));
|
|
2124
2403
|
router.use("/", createAgentMemoryRouter(agents));
|
|
2125
2404
|
router.use("/", createRoomManagementRouter(agents));
|
|
2126
2405
|
return router;
|
|
2127
2406
|
}
|
|
2128
2407
|
|
|
2129
2408
|
// src/api/messaging/index.ts
|
|
2130
|
-
import
|
|
2409
|
+
import express14 from "express";
|
|
2131
2410
|
|
|
2132
2411
|
// src/api/messaging/core.ts
|
|
2133
|
-
import { logger as logger8, validateUuid as
|
|
2134
|
-
import
|
|
2412
|
+
import { logger as logger8, validateUuid as validateUuid9 } from "@elizaos/core";
|
|
2413
|
+
import express10 from "express";
|
|
2135
2414
|
|
|
2136
2415
|
// src/bus.ts
|
|
2137
2416
|
class InternalMessageBus extends EventTarget {
|
|
@@ -2202,7 +2481,7 @@ var bus_default = internalMessageBus;
|
|
|
2202
2481
|
// src/api/messaging/core.ts
|
|
2203
2482
|
var DEFAULT_SERVER_ID = "00000000-0000-0000-0000-000000000000";
|
|
2204
2483
|
function createMessagingCoreRouter(serverInstance) {
|
|
2205
|
-
const router =
|
|
2484
|
+
const router = express10.Router();
|
|
2206
2485
|
router.post("/submit", async (req, res) => {
|
|
2207
2486
|
const {
|
|
2208
2487
|
channel_id,
|
|
@@ -2214,14 +2493,14 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2214
2493
|
raw_message,
|
|
2215
2494
|
metadata
|
|
2216
2495
|
} = req.body;
|
|
2217
|
-
const isValidServerId = server_id === DEFAULT_SERVER_ID ||
|
|
2218
|
-
if (!
|
|
2496
|
+
const isValidServerId = server_id === DEFAULT_SERVER_ID || validateUuid9(server_id);
|
|
2497
|
+
if (!validateUuid9(channel_id) || !validateUuid9(author_id) || !content || !isValidServerId || !source_type || !raw_message) {
|
|
2219
2498
|
return res.status(400).json({
|
|
2220
2499
|
success: false,
|
|
2221
2500
|
error: "Missing required fields: channel_id, server_id, author_id, content, source_type, raw_message"
|
|
2222
2501
|
});
|
|
2223
2502
|
}
|
|
2224
|
-
if (in_reply_to_message_id && !
|
|
2503
|
+
if (in_reply_to_message_id && !validateUuid9(in_reply_to_message_id)) {
|
|
2225
2504
|
return res.status(400).json({
|
|
2226
2505
|
success: false,
|
|
2227
2506
|
error: "Invalid in_reply_to_message_id format"
|
|
@@ -2229,12 +2508,12 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2229
2508
|
}
|
|
2230
2509
|
try {
|
|
2231
2510
|
const newRootMessageData = {
|
|
2232
|
-
channelId:
|
|
2233
|
-
authorId:
|
|
2511
|
+
channelId: validateUuid9(channel_id),
|
|
2512
|
+
authorId: validateUuid9(author_id),
|
|
2234
2513
|
content,
|
|
2235
2514
|
rawMessage: raw_message,
|
|
2236
2515
|
sourceType: source_type || "agent_response",
|
|
2237
|
-
inReplyToRootMessageId: in_reply_to_message_id ?
|
|
2516
|
+
inReplyToRootMessageId: in_reply_to_message_id ? validateUuid9(in_reply_to_message_id) || undefined : undefined,
|
|
2238
2517
|
metadata
|
|
2239
2518
|
};
|
|
2240
2519
|
const createdMessage = await serverInstance.createMessage(newRootMessageData);
|
|
@@ -2271,28 +2550,28 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2271
2550
|
raw_message,
|
|
2272
2551
|
metadata
|
|
2273
2552
|
} = req.body;
|
|
2274
|
-
const isValidServerId = server_id === DEFAULT_SERVER_ID ||
|
|
2275
|
-
if (!
|
|
2553
|
+
const isValidServerId = server_id === DEFAULT_SERVER_ID || validateUuid9(server_id);
|
|
2554
|
+
if (!validateUuid9(channel_id) || !validateUuid9(author_id) || !content || !isValidServerId || !source_type || !raw_message) {
|
|
2276
2555
|
return res.status(400).json({
|
|
2277
2556
|
success: false,
|
|
2278
2557
|
error: "Missing required fields: channel_id, server_id, author_id, content, source_type, raw_message"
|
|
2279
2558
|
});
|
|
2280
2559
|
}
|
|
2281
|
-
if (in_reply_to_message_id && !
|
|
2560
|
+
if (in_reply_to_message_id && !validateUuid9(in_reply_to_message_id)) {
|
|
2282
2561
|
return res.status(400).json({ success: false, error: "Invalid in_reply_to_message_id format" });
|
|
2283
2562
|
}
|
|
2284
|
-
if (messageId && !
|
|
2563
|
+
if (messageId && !validateUuid9(messageId)) {
|
|
2285
2564
|
return res.status(400).json({ success: false, error: "Invalid messageId format" });
|
|
2286
2565
|
}
|
|
2287
2566
|
try {
|
|
2288
2567
|
const baseData = {
|
|
2289
2568
|
messageId,
|
|
2290
|
-
channelId:
|
|
2291
|
-
authorId:
|
|
2569
|
+
channelId: validateUuid9(channel_id),
|
|
2570
|
+
authorId: validateUuid9(author_id),
|
|
2292
2571
|
content,
|
|
2293
2572
|
rawMessage: raw_message,
|
|
2294
2573
|
sourceType: source_type || "agent_response",
|
|
2295
|
-
inReplyToRootMessageId: in_reply_to_message_id ?
|
|
2574
|
+
inReplyToRootMessageId: in_reply_to_message_id ? validateUuid9(in_reply_to_message_id) || undefined : undefined,
|
|
2296
2575
|
metadata
|
|
2297
2576
|
};
|
|
2298
2577
|
const savedMessage = await serverInstance.createMessage(baseData);
|
|
@@ -2321,7 +2600,7 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2321
2600
|
});
|
|
2322
2601
|
router.patch("/action/:id", async (req, res) => {
|
|
2323
2602
|
const { id } = req.params;
|
|
2324
|
-
if (!
|
|
2603
|
+
if (!validateUuid9(id)) {
|
|
2325
2604
|
return res.status(400).json({ success: false, error: "Invalid message id" });
|
|
2326
2605
|
}
|
|
2327
2606
|
const {
|
|
@@ -2333,13 +2612,13 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2333
2612
|
author_id,
|
|
2334
2613
|
server_id
|
|
2335
2614
|
} = req.body ?? {};
|
|
2336
|
-
if (in_reply_to_message_id && !
|
|
2615
|
+
if (in_reply_to_message_id && !validateUuid9(in_reply_to_message_id)) {
|
|
2337
2616
|
return res.status(400).json({ success: false, error: "Invalid in_reply_to_message_id format" });
|
|
2338
2617
|
}
|
|
2339
|
-
if (author_id && !
|
|
2618
|
+
if (author_id && !validateUuid9(author_id)) {
|
|
2340
2619
|
return res.status(400).json({ success: false, error: "Invalid author_id format" });
|
|
2341
2620
|
}
|
|
2342
|
-
if (server_id && !(server_id === DEFAULT_SERVER_ID ||
|
|
2621
|
+
if (server_id && !(server_id === DEFAULT_SERVER_ID || validateUuid9(server_id))) {
|
|
2343
2622
|
return res.status(400).json({ success: false, error: "Invalid server_id format" });
|
|
2344
2623
|
}
|
|
2345
2624
|
try {
|
|
@@ -2347,7 +2626,7 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2347
2626
|
content,
|
|
2348
2627
|
rawMessage: raw_message,
|
|
2349
2628
|
sourceType: source_type,
|
|
2350
|
-
inReplyToRootMessageId: in_reply_to_message_id ?
|
|
2629
|
+
inReplyToRootMessageId: in_reply_to_message_id ? validateUuid9(in_reply_to_message_id) || undefined : undefined,
|
|
2351
2630
|
metadata
|
|
2352
2631
|
});
|
|
2353
2632
|
if (!updated) {
|
|
@@ -2389,7 +2668,7 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2389
2668
|
rawMessage: messagePayload.raw_message,
|
|
2390
2669
|
sourceId: messagePayload.source_id,
|
|
2391
2670
|
sourceType: messagePayload.source_type,
|
|
2392
|
-
inReplyToRootMessageId: messagePayload.in_reply_to_message_id ?
|
|
2671
|
+
inReplyToRootMessageId: messagePayload.in_reply_to_message_id ? validateUuid9(messagePayload.in_reply_to_message_id) || undefined : undefined,
|
|
2393
2672
|
metadata: messagePayload.metadata
|
|
2394
2673
|
};
|
|
2395
2674
|
const createdRootMessage = await serverInstance.createMessage(messageToCreate);
|
|
@@ -2435,11 +2714,11 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
2435
2714
|
}
|
|
2436
2715
|
|
|
2437
2716
|
// src/api/messaging/servers.ts
|
|
2438
|
-
import { logger as logger9, validateUuid as
|
|
2439
|
-
import
|
|
2717
|
+
import { logger as logger9, validateUuid as validateUuid10 } from "@elizaos/core";
|
|
2718
|
+
import express11 from "express";
|
|
2440
2719
|
var DEFAULT_SERVER_ID2 = "00000000-0000-0000-0000-000000000000";
|
|
2441
2720
|
function createServersRouter(serverInstance) {
|
|
2442
|
-
const router =
|
|
2721
|
+
const router = express11.Router();
|
|
2443
2722
|
router.get("/central-servers", async (_req, res) => {
|
|
2444
2723
|
try {
|
|
2445
2724
|
const servers = await serverInstance.getServers();
|
|
@@ -2471,9 +2750,9 @@ function createServersRouter(serverInstance) {
|
|
|
2471
2750
|
}
|
|
2472
2751
|
});
|
|
2473
2752
|
router.post("/servers/:serverId/agents", async (req, res) => {
|
|
2474
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 :
|
|
2753
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 : validateUuid10(req.params.serverId);
|
|
2475
2754
|
const { agentId } = req.body;
|
|
2476
|
-
if (!serverId || !
|
|
2755
|
+
if (!serverId || !validateUuid10(agentId)) {
|
|
2477
2756
|
return res.status(400).json({
|
|
2478
2757
|
success: false,
|
|
2479
2758
|
error: "Invalid serverId or agentId format"
|
|
@@ -2501,8 +2780,8 @@ function createServersRouter(serverInstance) {
|
|
|
2501
2780
|
}
|
|
2502
2781
|
});
|
|
2503
2782
|
router.delete("/servers/:serverId/agents/:agentId", async (req, res) => {
|
|
2504
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 :
|
|
2505
|
-
const agentId =
|
|
2783
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 : validateUuid10(req.params.serverId);
|
|
2784
|
+
const agentId = validateUuid10(req.params.agentId);
|
|
2506
2785
|
if (!serverId || !agentId) {
|
|
2507
2786
|
return res.status(400).json({
|
|
2508
2787
|
success: false,
|
|
@@ -2531,7 +2810,7 @@ function createServersRouter(serverInstance) {
|
|
|
2531
2810
|
}
|
|
2532
2811
|
});
|
|
2533
2812
|
router.get("/servers/:serverId/agents", async (req, res) => {
|
|
2534
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 :
|
|
2813
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 : validateUuid10(req.params.serverId);
|
|
2535
2814
|
if (!serverId) {
|
|
2536
2815
|
return res.status(400).json({
|
|
2537
2816
|
success: false,
|
|
@@ -2553,7 +2832,7 @@ function createServersRouter(serverInstance) {
|
|
|
2553
2832
|
}
|
|
2554
2833
|
});
|
|
2555
2834
|
router.get("/agents/:agentId/servers", async (req, res) => {
|
|
2556
|
-
const agentId =
|
|
2835
|
+
const agentId = validateUuid10(req.params.agentId);
|
|
2557
2836
|
if (!agentId) {
|
|
2558
2837
|
return res.status(400).json({
|
|
2559
2838
|
success: false,
|
|
@@ -2583,15 +2862,15 @@ import {
|
|
|
2583
2862
|
ModelType,
|
|
2584
2863
|
ChannelType as ChannelType2,
|
|
2585
2864
|
logger as logger12,
|
|
2586
|
-
validateUuid as
|
|
2865
|
+
validateUuid as validateUuid13
|
|
2587
2866
|
} from "@elizaos/core";
|
|
2588
|
-
import
|
|
2867
|
+
import express12 from "express";
|
|
2589
2868
|
|
|
2590
2869
|
// src/api/shared/middleware.ts
|
|
2591
|
-
import { validateUuid as
|
|
2870
|
+
import { validateUuid as validateUuid12, logger as logger11 } from "@elizaos/core";
|
|
2592
2871
|
|
|
2593
2872
|
// src/api/shared/validation.ts
|
|
2594
|
-
import { validateUuid as
|
|
2873
|
+
import { validateUuid as validateUuid11, logger as logger10 } from "@elizaos/core";
|
|
2595
2874
|
var getRuntime = (agents, agentId) => {
|
|
2596
2875
|
const runtime = agents.get(agentId);
|
|
2597
2876
|
if (!runtime) {
|
|
@@ -3336,9 +3615,9 @@ async function saveChannelUploadedFile(file, channelId) {
|
|
|
3336
3615
|
return { filename, url };
|
|
3337
3616
|
}
|
|
3338
3617
|
function createChannelsRouter(agents, serverInstance) {
|
|
3339
|
-
const router =
|
|
3618
|
+
const router = express12.Router();
|
|
3340
3619
|
router.post("/central-channels/:channelId/messages", async (req, res) => {
|
|
3341
|
-
const channelIdParam =
|
|
3620
|
+
const channelIdParam = validateUuid13(req.params.channelId);
|
|
3342
3621
|
const {
|
|
3343
3622
|
author_id,
|
|
3344
3623
|
content,
|
|
@@ -3348,8 +3627,8 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3348
3627
|
metadata,
|
|
3349
3628
|
source_type
|
|
3350
3629
|
} = req.body;
|
|
3351
|
-
const isValidServerId = server_id === DEFAULT_SERVER_ID3 ||
|
|
3352
|
-
if (!channelIdParam || !
|
|
3630
|
+
const isValidServerId = server_id === DEFAULT_SERVER_ID3 || validateUuid13(server_id);
|
|
3631
|
+
if (!channelIdParam || !validateUuid13(author_id) || !content || !isValidServerId) {
|
|
3353
3632
|
return res.status(400).json({
|
|
3354
3633
|
success: false,
|
|
3355
3634
|
error: "Missing required fields: channelId, server_id, author_id, content"
|
|
@@ -3395,7 +3674,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3395
3674
|
const participants = [author_id];
|
|
3396
3675
|
if (isDmChannel) {
|
|
3397
3676
|
const otherParticipant = metadata?.targetUserId || metadata?.recipientId;
|
|
3398
|
-
if (otherParticipant &&
|
|
3677
|
+
if (otherParticipant && validateUuid13(otherParticipant)) {
|
|
3399
3678
|
participants.push(otherParticipant);
|
|
3400
3679
|
logger12.info(`[Messages Router] DM channel will include participants: ${participants.join(", ")}`);
|
|
3401
3680
|
} else {
|
|
@@ -3416,7 +3695,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3416
3695
|
channelId: channelIdParam,
|
|
3417
3696
|
authorId: author_id,
|
|
3418
3697
|
content,
|
|
3419
|
-
inReplyToRootMessageId: in_reply_to_message_id ?
|
|
3698
|
+
inReplyToRootMessageId: in_reply_to_message_id ? validateUuid13(in_reply_to_message_id) || undefined : undefined,
|
|
3420
3699
|
rawMessage: raw_message,
|
|
3421
3700
|
metadata,
|
|
3422
3701
|
sourceType: source_type || "eliza_gui"
|
|
@@ -3460,7 +3739,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3460
3739
|
}
|
|
3461
3740
|
});
|
|
3462
3741
|
router.get("/central-channels/:channelId/messages", async (req, res) => {
|
|
3463
|
-
const channelId =
|
|
3742
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3464
3743
|
const limit = req.query.limit ? Number.parseInt(req.query.limit, 10) : 50;
|
|
3465
3744
|
const before = req.query.before ? Number.parseInt(req.query.before, 10) : undefined;
|
|
3466
3745
|
const beforeDate = before ? new Date(before) : undefined;
|
|
@@ -3489,7 +3768,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3489
3768
|
}
|
|
3490
3769
|
});
|
|
3491
3770
|
router.get("/central-servers/:serverId/channels", async (req, res) => {
|
|
3492
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 :
|
|
3771
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 : validateUuid13(req.params.serverId);
|
|
3493
3772
|
if (!serverId) {
|
|
3494
3773
|
return res.status(400).json({ success: false, error: "Invalid serverId" });
|
|
3495
3774
|
}
|
|
@@ -3523,7 +3802,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3523
3802
|
error: "Missing required fields: type."
|
|
3524
3803
|
});
|
|
3525
3804
|
}
|
|
3526
|
-
if (!
|
|
3805
|
+
if (!validateUuid13(serverId)) {
|
|
3527
3806
|
return res.status(400).json({
|
|
3528
3807
|
success: false,
|
|
3529
3808
|
error: "Invalid serverId format"
|
|
@@ -3546,9 +3825,9 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3546
3825
|
}
|
|
3547
3826
|
});
|
|
3548
3827
|
router.get("/dm-channel", async (req, res) => {
|
|
3549
|
-
const targetUserId =
|
|
3550
|
-
const currentUserId =
|
|
3551
|
-
const providedDmServerId = req.query.dmServerId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 :
|
|
3828
|
+
const targetUserId = validateUuid13(req.query.targetUserId);
|
|
3829
|
+
const currentUserId = validateUuid13(req.query.currentUserId);
|
|
3830
|
+
const providedDmServerId = req.query.dmServerId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 : validateUuid13(req.query.dmServerId);
|
|
3552
3831
|
if (!targetUserId || !currentUserId) {
|
|
3553
3832
|
res.status(400).json({ success: false, error: "Missing targetUserId or currentUserId" });
|
|
3554
3833
|
return;
|
|
@@ -3588,8 +3867,8 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3588
3867
|
server_id,
|
|
3589
3868
|
metadata
|
|
3590
3869
|
} = req.body;
|
|
3591
|
-
const isValidServerId = server_id === DEFAULT_SERVER_ID3 ||
|
|
3592
|
-
if (!name || !isValidServerId || !Array.isArray(participantCentralUserIds) || participantCentralUserIds.some((id) => !
|
|
3870
|
+
const isValidServerId = server_id === DEFAULT_SERVER_ID3 || validateUuid13(server_id);
|
|
3871
|
+
if (!name || !isValidServerId || !Array.isArray(participantCentralUserIds) || participantCentralUserIds.some((id) => !validateUuid13(id))) {
|
|
3593
3872
|
return res.status(400).json({
|
|
3594
3873
|
success: false,
|
|
3595
3874
|
error: 'Invalid payload. Required: name, server_id (UUID or "0"), participantCentralUserIds (array of UUIDs). Optional: type, metadata.'
|
|
@@ -3613,7 +3892,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3613
3892
|
}
|
|
3614
3893
|
});
|
|
3615
3894
|
router.get("/central-channels/:channelId/details", async (req, res) => {
|
|
3616
|
-
const channelId =
|
|
3895
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3617
3896
|
if (!channelId) {
|
|
3618
3897
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
3619
3898
|
}
|
|
@@ -3629,7 +3908,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3629
3908
|
}
|
|
3630
3909
|
});
|
|
3631
3910
|
router.get("/central-channels/:channelId/participants", async (req, res) => {
|
|
3632
|
-
const channelId =
|
|
3911
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3633
3912
|
if (!channelId) {
|
|
3634
3913
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
3635
3914
|
}
|
|
@@ -3642,9 +3921,9 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3642
3921
|
}
|
|
3643
3922
|
});
|
|
3644
3923
|
router.post("/central-channels/:channelId/agents", async (req, res) => {
|
|
3645
|
-
const channelId =
|
|
3924
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3646
3925
|
const { agentId } = req.body;
|
|
3647
|
-
if (!channelId || !
|
|
3926
|
+
if (!channelId || !validateUuid13(agentId)) {
|
|
3648
3927
|
return res.status(400).json({
|
|
3649
3928
|
success: false,
|
|
3650
3929
|
error: "Invalid channelId or agentId format"
|
|
@@ -3678,8 +3957,8 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3678
3957
|
}
|
|
3679
3958
|
});
|
|
3680
3959
|
router.delete("/central-channels/:channelId/agents/:agentId", async (req, res) => {
|
|
3681
|
-
const channelId =
|
|
3682
|
-
const agentId =
|
|
3960
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3961
|
+
const agentId = validateUuid13(req.params.agentId);
|
|
3683
3962
|
if (!channelId || !agentId) {
|
|
3684
3963
|
return res.status(400).json({
|
|
3685
3964
|
success: false,
|
|
@@ -3724,7 +4003,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3724
4003
|
}
|
|
3725
4004
|
});
|
|
3726
4005
|
router.get("/central-channels/:channelId/agents", async (req, res) => {
|
|
3727
|
-
const channelId =
|
|
4006
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3728
4007
|
if (!channelId) {
|
|
3729
4008
|
return res.status(400).json({
|
|
3730
4009
|
success: false,
|
|
@@ -3749,8 +4028,8 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3749
4028
|
}
|
|
3750
4029
|
});
|
|
3751
4030
|
router.delete("/central-channels/:channelId/messages/:messageId", async (req, res) => {
|
|
3752
|
-
const channelId =
|
|
3753
|
-
const messageId =
|
|
4031
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
4032
|
+
const messageId = validateUuid13(req.params.messageId);
|
|
3754
4033
|
if (!channelId || !messageId) {
|
|
3755
4034
|
return res.status(400).json({ success: false, error: "Invalid channelId or messageId" });
|
|
3756
4035
|
}
|
|
@@ -3776,7 +4055,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3776
4055
|
}
|
|
3777
4056
|
});
|
|
3778
4057
|
router.delete("/central-channels/:channelId/messages", async (req, res) => {
|
|
3779
|
-
const channelId =
|
|
4058
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3780
4059
|
if (!channelId) {
|
|
3781
4060
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
3782
4061
|
}
|
|
@@ -3799,7 +4078,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3799
4078
|
}
|
|
3800
4079
|
});
|
|
3801
4080
|
router.patch("/central-channels/:channelId", async (req, res) => {
|
|
3802
|
-
const channelId =
|
|
4081
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3803
4082
|
if (!channelId) {
|
|
3804
4083
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
3805
4084
|
}
|
|
@@ -3823,7 +4102,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3823
4102
|
}
|
|
3824
4103
|
});
|
|
3825
4104
|
router.delete("/central-channels/:channelId", async (req, res) => {
|
|
3826
|
-
const channelId =
|
|
4105
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3827
4106
|
if (!channelId) {
|
|
3828
4107
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
3829
4108
|
}
|
|
@@ -3849,7 +4128,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3849
4128
|
}
|
|
3850
4129
|
});
|
|
3851
4130
|
router.post("/channels/:channelId/upload-media", createUploadRateLimit(), createFileSystemRateLimit(), channelUploadMiddleware.single("file"), async (req, res) => {
|
|
3852
|
-
const channelId =
|
|
4131
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3853
4132
|
if (!channelId) {
|
|
3854
4133
|
res.status(400).json({ success: false, error: "Invalid channelId format" });
|
|
3855
4134
|
return;
|
|
@@ -3882,7 +4161,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3882
4161
|
}
|
|
3883
4162
|
});
|
|
3884
4163
|
router.post("/central-channels/:channelId/generate-title", async (req, res) => {
|
|
3885
|
-
const channelId =
|
|
4164
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
3886
4165
|
const { agentId } = req.body;
|
|
3887
4166
|
if (!channelId) {
|
|
3888
4167
|
return res.status(400).json({
|
|
@@ -3890,7 +4169,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
3890
4169
|
error: "Invalid channel ID format"
|
|
3891
4170
|
});
|
|
3892
4171
|
}
|
|
3893
|
-
if (!agentId || !
|
|
4172
|
+
if (!agentId || !validateUuid13(agentId)) {
|
|
3894
4173
|
return res.status(400).json({
|
|
3895
4174
|
success: false,
|
|
3896
4175
|
error: "Valid agent ID is required"
|
|
@@ -3984,8 +4263,8 @@ Respond with just the title, nothing else.
|
|
|
3984
4263
|
}
|
|
3985
4264
|
|
|
3986
4265
|
// src/api/messaging/sessions.ts
|
|
3987
|
-
import { logger as logger13, validateUuid as
|
|
3988
|
-
import
|
|
4266
|
+
import { logger as logger13, validateUuid as validateUuid14, ChannelType as ChannelType3 } from "@elizaos/core";
|
|
4267
|
+
import express13 from "express";
|
|
3989
4268
|
|
|
3990
4269
|
// ../../node_modules/uuid/dist/esm/stringify.js
|
|
3991
4270
|
var byteToHex = [];
|
|
@@ -4404,7 +4683,7 @@ function asyncHandler(fn) {
|
|
|
4404
4683
|
};
|
|
4405
4684
|
}
|
|
4406
4685
|
function createSessionsRouter(agents, serverInstance) {
|
|
4407
|
-
const router =
|
|
4686
|
+
const router = express13.Router();
|
|
4408
4687
|
router.get("/sessions/health", (_req, res) => {
|
|
4409
4688
|
const now = Date.now();
|
|
4410
4689
|
let activeSessions = 0;
|
|
@@ -4437,10 +4716,10 @@ function createSessionsRouter(agents, serverInstance) {
|
|
|
4437
4716
|
if (!isCreateSessionRequest(body)) {
|
|
4438
4717
|
throw new MissingFieldsError(["agentId", "userId"]);
|
|
4439
4718
|
}
|
|
4440
|
-
if (!
|
|
4719
|
+
if (!validateUuid14(body.agentId)) {
|
|
4441
4720
|
throw new InvalidUuidError("agentId", body.agentId);
|
|
4442
4721
|
}
|
|
4443
|
-
if (!
|
|
4722
|
+
if (!validateUuid14(body.userId)) {
|
|
4444
4723
|
throw new InvalidUuidError("userId", body.userId);
|
|
4445
4724
|
}
|
|
4446
4725
|
const agent = agents.get(body.agentId);
|
|
@@ -4858,7 +5137,7 @@ function createSessionsRouter(agents, serverInstance) {
|
|
|
4858
5137
|
|
|
4859
5138
|
// src/api/messaging/index.ts
|
|
4860
5139
|
function messagingRouter(agents, serverInstance) {
|
|
4861
|
-
const router =
|
|
5140
|
+
const router = express14.Router();
|
|
4862
5141
|
if (!serverInstance) {
|
|
4863
5142
|
throw new Error("ServerInstance is required for messaging router");
|
|
4864
5143
|
}
|
|
@@ -4870,11 +5149,11 @@ function messagingRouter(agents, serverInstance) {
|
|
|
4870
5149
|
}
|
|
4871
5150
|
|
|
4872
5151
|
// src/api/media/index.ts
|
|
4873
|
-
import
|
|
5152
|
+
import express17 from "express";
|
|
4874
5153
|
|
|
4875
5154
|
// src/api/media/agents.ts
|
|
4876
|
-
import { validateUuid as
|
|
4877
|
-
import
|
|
5155
|
+
import { validateUuid as validateUuid15, logger as logger14, getContentTypeFromMimeType } from "@elizaos/core";
|
|
5156
|
+
import express15 from "express";
|
|
4878
5157
|
import multer2 from "multer";
|
|
4879
5158
|
import fs2 from "fs";
|
|
4880
5159
|
import path2 from "path";
|
|
@@ -4908,10 +5187,10 @@ async function saveUploadedFile(file, agentId) {
|
|
|
4908
5187
|
return { filename, url };
|
|
4909
5188
|
}
|
|
4910
5189
|
function createAgentMediaRouter() {
|
|
4911
|
-
const router =
|
|
5190
|
+
const router = express15.Router();
|
|
4912
5191
|
router.post("/:agentId/upload-media", upload.single("file"), async (req, res) => {
|
|
4913
5192
|
logger14.debug("[MEDIA UPLOAD] Processing media upload with multer");
|
|
4914
|
-
const agentId =
|
|
5193
|
+
const agentId = validateUuid15(req.params.agentId);
|
|
4915
5194
|
if (!agentId) {
|
|
4916
5195
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
4917
5196
|
}
|
|
@@ -4941,8 +5220,8 @@ function createAgentMediaRouter() {
|
|
|
4941
5220
|
}
|
|
4942
5221
|
|
|
4943
5222
|
// src/api/media/channels.ts
|
|
4944
|
-
import { validateUuid as
|
|
4945
|
-
import
|
|
5223
|
+
import { validateUuid as validateUuid16, logger as logger15 } from "@elizaos/core";
|
|
5224
|
+
import express16 from "express";
|
|
4946
5225
|
import multer3 from "multer";
|
|
4947
5226
|
import fs3 from "fs";
|
|
4948
5227
|
import path3 from "path";
|
|
@@ -4977,14 +5256,14 @@ async function saveUploadedFile2(file, channelId) {
|
|
|
4977
5256
|
return { filename, url };
|
|
4978
5257
|
}
|
|
4979
5258
|
function createChannelMediaRouter() {
|
|
4980
|
-
const router =
|
|
5259
|
+
const router = express16.Router();
|
|
4981
5260
|
const uploadMediaRateLimiter = lib_default({
|
|
4982
5261
|
windowMs: 15 * 60 * 1000,
|
|
4983
5262
|
max: 100,
|
|
4984
5263
|
message: { success: false, error: "Too many requests, please try again later." }
|
|
4985
5264
|
});
|
|
4986
5265
|
router.post("/:channelId/upload-media", uploadMediaRateLimiter, upload2.single("file"), async (req, res) => {
|
|
4987
|
-
const channelId =
|
|
5266
|
+
const channelId = validateUuid16(req.params.channelId);
|
|
4988
5267
|
if (!channelId) {
|
|
4989
5268
|
res.status(400).json({ success: false, error: "Invalid channelId format" });
|
|
4990
5269
|
return;
|
|
@@ -5016,18 +5295,18 @@ function createChannelMediaRouter() {
|
|
|
5016
5295
|
|
|
5017
5296
|
// src/api/media/index.ts
|
|
5018
5297
|
function mediaRouter() {
|
|
5019
|
-
const router =
|
|
5298
|
+
const router = express17.Router();
|
|
5020
5299
|
router.use("/agents", createAgentMediaRouter());
|
|
5021
5300
|
router.use("/channels", createChannelMediaRouter());
|
|
5022
5301
|
return router;
|
|
5023
5302
|
}
|
|
5024
5303
|
|
|
5025
5304
|
// src/api/memory/index.ts
|
|
5026
|
-
import
|
|
5305
|
+
import express19 from "express";
|
|
5027
5306
|
|
|
5028
5307
|
// src/api/memory/groups.ts
|
|
5029
|
-
import { validateUuid as
|
|
5030
|
-
import
|
|
5308
|
+
import { validateUuid as validateUuid18, logger as logger18, createUniqueUuid as createUniqueUuid4, ChannelType as ChannelType4 } from "@elizaos/core";
|
|
5309
|
+
import express18 from "express";
|
|
5031
5310
|
// src/api/shared/file-utils.ts
|
|
5032
5311
|
import { logger as logger16 } from "@elizaos/core";
|
|
5033
5312
|
var cleanupUploadedFile = (file) => {
|
|
@@ -5035,7 +5314,7 @@ var cleanupUploadedFile = (file) => {
|
|
|
5035
5314
|
};
|
|
5036
5315
|
// src/upload.ts
|
|
5037
5316
|
import multer4 from "multer";
|
|
5038
|
-
import { validateUuid as
|
|
5317
|
+
import { validateUuid as validateUuid17, logger as logger17 } from "@elizaos/core";
|
|
5039
5318
|
var storage3 = multer4.memoryStorage();
|
|
5040
5319
|
var agentAudioUpload = () => multer4({
|
|
5041
5320
|
storage: storage3,
|
|
@@ -5057,10 +5336,10 @@ function validateAudioFile(file) {
|
|
|
5057
5336
|
}
|
|
5058
5337
|
// src/api/memory/groups.ts
|
|
5059
5338
|
function createGroupMemoryRouter(agents, serverInstance) {
|
|
5060
|
-
const router =
|
|
5339
|
+
const router = express18.Router();
|
|
5061
5340
|
const db = serverInstance?.database;
|
|
5062
5341
|
router.post("/groups/:serverId", async (req, res) => {
|
|
5063
|
-
const serverId =
|
|
5342
|
+
const serverId = validateUuid18(req.params.serverId);
|
|
5064
5343
|
const { name, worldId, source, metadata, agentIds = [] } = req.body;
|
|
5065
5344
|
if (!Array.isArray(agentIds) || agentIds.length === 0) {
|
|
5066
5345
|
return sendError(res, 400, "BAD_REQUEST", "agentIds must be a non-empty array");
|
|
@@ -5122,7 +5401,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
5122
5401
|
});
|
|
5123
5402
|
});
|
|
5124
5403
|
router.delete("/groups/:serverId", async (req, res) => {
|
|
5125
|
-
const worldId =
|
|
5404
|
+
const worldId = validateUuid18(req.params.serverId);
|
|
5126
5405
|
if (!worldId) {
|
|
5127
5406
|
return sendError(res, 400, "INVALID_ID", "Invalid serverId (worldId) format");
|
|
5128
5407
|
}
|
|
@@ -5138,7 +5417,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
5138
5417
|
}
|
|
5139
5418
|
});
|
|
5140
5419
|
router.delete("/groups/:serverId/memories", async (req, res) => {
|
|
5141
|
-
const worldId =
|
|
5420
|
+
const worldId = validateUuid18(req.params.serverId);
|
|
5142
5421
|
if (!worldId) {
|
|
5143
5422
|
return sendError(res, 400, "INVALID_ID", "Invalid serverId (worldId) format");
|
|
5144
5423
|
}
|
|
@@ -5162,7 +5441,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
5162
5441
|
|
|
5163
5442
|
// src/api/memory/index.ts
|
|
5164
5443
|
function memoryRouter(agents, serverInstance) {
|
|
5165
|
-
const router =
|
|
5444
|
+
const router = express19.Router();
|
|
5166
5445
|
router.use("/", createAgentMemoryRouter(agents));
|
|
5167
5446
|
router.use("/", createGroupMemoryRouter(agents, serverInstance));
|
|
5168
5447
|
router.use("/", createRoomManagementRouter(agents));
|
|
@@ -5170,19 +5449,19 @@ function memoryRouter(agents, serverInstance) {
|
|
|
5170
5449
|
}
|
|
5171
5450
|
|
|
5172
5451
|
// src/api/audio/index.ts
|
|
5173
|
-
import
|
|
5452
|
+
import express23 from "express";
|
|
5174
5453
|
|
|
5175
5454
|
// src/api/audio/processing.ts
|
|
5176
|
-
import { logger as logger19, ModelType as ModelType2, validateUuid as
|
|
5177
|
-
import
|
|
5455
|
+
import { logger as logger19, ModelType as ModelType2, validateUuid as validateUuid19 } from "@elizaos/core";
|
|
5456
|
+
import express20 from "express";
|
|
5178
5457
|
function createAudioProcessingRouter(agents) {
|
|
5179
|
-
const router =
|
|
5458
|
+
const router = express20.Router();
|
|
5180
5459
|
router.use(createUploadRateLimit());
|
|
5181
5460
|
router.use(createFileSystemRateLimit());
|
|
5182
5461
|
router.post("/:agentId/audio-messages", agentAudioUpload().single("file"), async (req, res) => {
|
|
5183
5462
|
const audioReq = req;
|
|
5184
5463
|
logger19.debug("[AUDIO MESSAGE] Processing audio message");
|
|
5185
|
-
const agentId =
|
|
5464
|
+
const agentId = validateUuid19(req.params.agentId);
|
|
5186
5465
|
if (!agentId) {
|
|
5187
5466
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
5188
5467
|
}
|
|
@@ -5217,7 +5496,7 @@ function createAudioProcessingRouter(agents) {
|
|
|
5217
5496
|
router.post("/:agentId/transcriptions", agentAudioUpload().single("file"), async (req, res) => {
|
|
5218
5497
|
const audioReq = req;
|
|
5219
5498
|
logger19.debug("[TRANSCRIPTION] Request to transcribe audio");
|
|
5220
|
-
const agentId =
|
|
5499
|
+
const agentId = validateUuid19(req.params.agentId);
|
|
5221
5500
|
if (!agentId) {
|
|
5222
5501
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
5223
5502
|
}
|
|
@@ -5258,8 +5537,8 @@ function createAudioProcessingRouter(agents) {
|
|
|
5258
5537
|
}
|
|
5259
5538
|
|
|
5260
5539
|
// src/api/audio/synthesis.ts
|
|
5261
|
-
import { validateUuid as
|
|
5262
|
-
import
|
|
5540
|
+
import { validateUuid as validateUuid20, logger as logger20, ModelType as ModelType3 } from "@elizaos/core";
|
|
5541
|
+
import express21 from "express";
|
|
5263
5542
|
|
|
5264
5543
|
// src/api/audio/audioBuffer.ts
|
|
5265
5544
|
import { Readable } from "node:stream";
|
|
@@ -5315,9 +5594,9 @@ async function convertToAudioBuffer(speechResponse, detectMimeType) {
|
|
|
5315
5594
|
|
|
5316
5595
|
// src/api/audio/synthesis.ts
|
|
5317
5596
|
function createSynthesisRouter(agents) {
|
|
5318
|
-
const router =
|
|
5597
|
+
const router = express21.Router();
|
|
5319
5598
|
router.post("/:agentId/audio-messages/synthesize", async (req, res) => {
|
|
5320
|
-
const agentId =
|
|
5599
|
+
const agentId = validateUuid20(req.params.agentId);
|
|
5321
5600
|
if (!agentId) {
|
|
5322
5601
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
5323
5602
|
}
|
|
@@ -5345,7 +5624,7 @@ function createSynthesisRouter(agents) {
|
|
|
5345
5624
|
});
|
|
5346
5625
|
router.post("/:agentId/speech/generate", async (req, res) => {
|
|
5347
5626
|
logger20.debug("[SPEECH GENERATE] Request to generate speech from text");
|
|
5348
|
-
const agentId =
|
|
5627
|
+
const agentId = validateUuid20(req.params.agentId);
|
|
5349
5628
|
if (!agentId) {
|
|
5350
5629
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
5351
5630
|
}
|
|
@@ -5379,7 +5658,7 @@ function createSynthesisRouter(agents) {
|
|
|
5379
5658
|
|
|
5380
5659
|
// src/api/audio/conversation.ts
|
|
5381
5660
|
import {
|
|
5382
|
-
validateUuid as
|
|
5661
|
+
validateUuid as validateUuid21,
|
|
5383
5662
|
logger as logger21,
|
|
5384
5663
|
ModelType as ModelType4,
|
|
5385
5664
|
ChannelType as ChannelType5,
|
|
@@ -5387,11 +5666,11 @@ import {
|
|
|
5387
5666
|
composePrompt,
|
|
5388
5667
|
messageHandlerTemplate
|
|
5389
5668
|
} from "@elizaos/core";
|
|
5390
|
-
import
|
|
5669
|
+
import express22 from "express";
|
|
5391
5670
|
function createConversationRouter(agents) {
|
|
5392
|
-
const router =
|
|
5671
|
+
const router = express22.Router();
|
|
5393
5672
|
router.post("/:agentId/speech/conversation", async (req, res) => {
|
|
5394
|
-
const agentId =
|
|
5673
|
+
const agentId = validateUuid21(req.params.agentId);
|
|
5395
5674
|
if (!agentId) {
|
|
5396
5675
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
5397
5676
|
}
|
|
@@ -5493,7 +5772,7 @@ function createConversationRouter(agents) {
|
|
|
5493
5772
|
|
|
5494
5773
|
// src/api/audio/index.ts
|
|
5495
5774
|
function audioRouter(agents) {
|
|
5496
|
-
const router =
|
|
5775
|
+
const router = express23.Router();
|
|
5497
5776
|
router.use("/", createAudioProcessingRouter(agents));
|
|
5498
5777
|
router.use("/", createSynthesisRouter(agents));
|
|
5499
5778
|
router.use("/", createConversationRouter(agents));
|
|
@@ -5501,13 +5780,13 @@ function audioRouter(agents) {
|
|
|
5501
5780
|
}
|
|
5502
5781
|
|
|
5503
5782
|
// src/api/runtime/index.ts
|
|
5504
|
-
import
|
|
5783
|
+
import express27 from "express";
|
|
5505
5784
|
|
|
5506
5785
|
// src/api/runtime/health.ts
|
|
5507
5786
|
import { logger as logger22 } from "@elizaos/core";
|
|
5508
|
-
import
|
|
5787
|
+
import express24 from "express";
|
|
5509
5788
|
function createHealthRouter(agents, serverInstance) {
|
|
5510
|
-
const router =
|
|
5789
|
+
const router = express24.Router();
|
|
5511
5790
|
router.get("/ping", (_req, res) => {
|
|
5512
5791
|
res.json({ pong: true, timestamp: Date.now() });
|
|
5513
5792
|
});
|
|
@@ -5548,7 +5827,7 @@ function createHealthRouter(agents, serverInstance) {
|
|
|
5548
5827
|
|
|
5549
5828
|
// src/api/runtime/logging.ts
|
|
5550
5829
|
import { logger as logger23, recentLogs } from "@elizaos/core";
|
|
5551
|
-
import
|
|
5830
|
+
import express25 from "express";
|
|
5552
5831
|
var LOG_LEVELS = {
|
|
5553
5832
|
fatal: 60,
|
|
5554
5833
|
error: 50,
|
|
@@ -5561,7 +5840,7 @@ var LOG_LEVELS = {
|
|
|
5561
5840
|
trace: 10
|
|
5562
5841
|
};
|
|
5563
5842
|
function createLoggingRouter() {
|
|
5564
|
-
const router =
|
|
5843
|
+
const router = express25.Router();
|
|
5565
5844
|
const logsHandler = async (req, res) => {
|
|
5566
5845
|
const since = req.query.since ? Number(req.query.since) : Date.now() - 3600000;
|
|
5567
5846
|
const requestedLevel = req.query.level?.toString().toLowerCase() || "all";
|
|
@@ -5681,9 +5960,9 @@ function createLoggingRouter() {
|
|
|
5681
5960
|
}
|
|
5682
5961
|
|
|
5683
5962
|
// src/api/runtime/debug.ts
|
|
5684
|
-
import
|
|
5963
|
+
import express26 from "express";
|
|
5685
5964
|
function createDebugRouter(serverInstance) {
|
|
5686
|
-
const router =
|
|
5965
|
+
const router = express26.Router();
|
|
5687
5966
|
router.get("/servers", async (_req, res) => {
|
|
5688
5967
|
try {
|
|
5689
5968
|
const servers = await serverInstance?.getServers();
|
|
@@ -5704,7 +5983,7 @@ function createDebugRouter(serverInstance) {
|
|
|
5704
5983
|
|
|
5705
5984
|
// src/api/runtime/index.ts
|
|
5706
5985
|
function runtimeRouter(agents, serverInstance) {
|
|
5707
|
-
const router =
|
|
5986
|
+
const router = express27.Router();
|
|
5708
5987
|
router.use("/", createHealthRouter(agents, serverInstance));
|
|
5709
5988
|
router.use("/", createLoggingRouter());
|
|
5710
5989
|
router.use("/debug", createDebugRouter(serverInstance));
|
|
@@ -5712,19 +5991,19 @@ function runtimeRouter(agents, serverInstance) {
|
|
|
5712
5991
|
}
|
|
5713
5992
|
|
|
5714
5993
|
// src/api/tee/index.ts
|
|
5715
|
-
import
|
|
5994
|
+
import express28 from "express";
|
|
5716
5995
|
function teeRouter() {
|
|
5717
|
-
const router =
|
|
5996
|
+
const router = express28.Router();
|
|
5718
5997
|
return router;
|
|
5719
5998
|
}
|
|
5720
5999
|
|
|
5721
6000
|
// src/api/system/index.ts
|
|
5722
|
-
import
|
|
6001
|
+
import express31 from "express";
|
|
5723
6002
|
|
|
5724
6003
|
// src/api/system/environment.ts
|
|
5725
6004
|
var import_dotenv = __toESM(require_main(), 1);
|
|
5726
6005
|
import { logger as logger24 } from "@elizaos/core";
|
|
5727
|
-
import
|
|
6006
|
+
import express29 from "express";
|
|
5728
6007
|
import { existsSync, writeFileSync } from "fs";
|
|
5729
6008
|
import path4 from "path";
|
|
5730
6009
|
import fs4 from "fs/promises";
|
|
@@ -5768,7 +6047,7 @@ function resolveEnvFile(startDir = process.cwd()) {
|
|
|
5768
6047
|
return path4.join(startDir, ".env");
|
|
5769
6048
|
}
|
|
5770
6049
|
function createEnvironmentRouter() {
|
|
5771
|
-
const router =
|
|
6050
|
+
const router = express29.Router();
|
|
5772
6051
|
router.get("/local", async (_req, res) => {
|
|
5773
6052
|
try {
|
|
5774
6053
|
const localEnvPath = getLocalEnvPath();
|
|
@@ -5835,11 +6114,11 @@ function createEnvironmentRouter() {
|
|
|
5835
6114
|
}
|
|
5836
6115
|
|
|
5837
6116
|
// src/api/system/version.ts
|
|
5838
|
-
import
|
|
6117
|
+
import express30 from "express";
|
|
5839
6118
|
// package.json
|
|
5840
6119
|
var package_default = {
|
|
5841
6120
|
name: "@elizaos/server",
|
|
5842
|
-
version: "1.5.8-alpha.
|
|
6121
|
+
version: "1.5.8-alpha.22",
|
|
5843
6122
|
description: "ElizaOS Server - Core server infrastructure for ElizaOS agents",
|
|
5844
6123
|
publishConfig: {
|
|
5845
6124
|
access: "public",
|
|
@@ -5931,7 +6210,7 @@ function getVersionInfo() {
|
|
|
5931
6210
|
}
|
|
5932
6211
|
}
|
|
5933
6212
|
function createVersionRouter() {
|
|
5934
|
-
const router =
|
|
6213
|
+
const router = express30.Router();
|
|
5935
6214
|
router.get("/", (_, res) => {
|
|
5936
6215
|
const versionInfo = getVersionInfo();
|
|
5937
6216
|
const statusCode = versionInfo.error ? 500 : 200;
|
|
@@ -5942,7 +6221,7 @@ function createVersionRouter() {
|
|
|
5942
6221
|
|
|
5943
6222
|
// src/api/system/index.ts
|
|
5944
6223
|
function systemRouter() {
|
|
5945
|
-
const router =
|
|
6224
|
+
const router = express31.Router();
|
|
5946
6225
|
router.use("/env", createEnvironmentRouter());
|
|
5947
6226
|
router.use("/version", createVersionRouter());
|
|
5948
6227
|
return router;
|
|
@@ -5953,7 +6232,7 @@ import {
|
|
|
5953
6232
|
logger as logger25,
|
|
5954
6233
|
customLevels,
|
|
5955
6234
|
SOCKET_MESSAGE_TYPE,
|
|
5956
|
-
validateUuid as
|
|
6235
|
+
validateUuid as validateUuid22,
|
|
5957
6236
|
ChannelType as ChannelType6,
|
|
5958
6237
|
EventType
|
|
5959
6238
|
} from "@elizaos/core";
|
|
@@ -6049,7 +6328,7 @@ class SocketIORouter {
|
|
|
6049
6328
|
return;
|
|
6050
6329
|
}
|
|
6051
6330
|
if (agentId) {
|
|
6052
|
-
const agentUuid =
|
|
6331
|
+
const agentUuid = validateUuid22(agentId);
|
|
6053
6332
|
if (agentUuid) {
|
|
6054
6333
|
this.connections.set(socket.id, agentUuid);
|
|
6055
6334
|
logger25.info(`[SocketIO] Socket ${socket.id} associated with agent ${agentUuid}`);
|
|
@@ -6087,7 +6366,7 @@ class SocketIORouter {
|
|
|
6087
6366
|
message: successMessage,
|
|
6088
6367
|
channelId,
|
|
6089
6368
|
roomId: channelId,
|
|
6090
|
-
...agentId && { agentId:
|
|
6369
|
+
...agentId && { agentId: validateUuid22(agentId) || agentId }
|
|
6091
6370
|
};
|
|
6092
6371
|
socket.emit("channel_joined", responsePayload);
|
|
6093
6372
|
socket.emit("room_joined", responsePayload);
|
|
@@ -6098,8 +6377,8 @@ class SocketIORouter {
|
|
|
6098
6377
|
const { senderId, senderName, message, serverId, source, metadata, attachments } = payload;
|
|
6099
6378
|
logger25.info(`[SocketIO ${socket.id}] Received SEND_MESSAGE for central submission: channel ${channelId} from ${senderName || senderId}`);
|
|
6100
6379
|
logger25.info(`[SocketIO ${socket.id}] Full payload for debugging:`, JSON.stringify(payload, null, 2));
|
|
6101
|
-
const isValidServerId = serverId === DEFAULT_SERVER_ID5 ||
|
|
6102
|
-
if (!
|
|
6380
|
+
const isValidServerId = serverId === DEFAULT_SERVER_ID5 || validateUuid22(serverId);
|
|
6381
|
+
if (!validateUuid22(channelId) || !isValidServerId || !validateUuid22(senderId) || !message) {
|
|
6103
6382
|
this.sendErrorResponse(socket, `For SEND_MESSAGE: channelId, serverId (server_id), senderId (author_id), and message are required.`);
|
|
6104
6383
|
return;
|
|
6105
6384
|
}
|
|
@@ -6163,7 +6442,7 @@ class SocketIORouter {
|
|
|
6163
6442
|
let participants = [senderId];
|
|
6164
6443
|
if (isDmChannel) {
|
|
6165
6444
|
const otherParticipant = metadata?.targetUserId || metadata?.recipientId || payload.targetUserId;
|
|
6166
|
-
if (otherParticipant &&
|
|
6445
|
+
if (otherParticipant && validateUuid22(otherParticipant)) {
|
|
6167
6446
|
participants.push(otherParticipant);
|
|
6168
6447
|
logger25.info(`[SocketIO ${socket.id}] DM channel will include participants: ${participants.join(", ")}`);
|
|
6169
6448
|
} else {
|
|
@@ -6433,7 +6712,7 @@ function createPluginRouteHandler(agents) {
|
|
|
6433
6712
|
}
|
|
6434
6713
|
return handled;
|
|
6435
6714
|
}
|
|
6436
|
-
if (agentIdFromQuery &&
|
|
6715
|
+
if (agentIdFromQuery && validateUuid23(agentIdFromQuery)) {
|
|
6437
6716
|
const runtime = agents.get(agentIdFromQuery);
|
|
6438
6717
|
if (runtime) {
|
|
6439
6718
|
logger26.debug(`Agent-scoped request for Agent ID: ${agentIdFromQuery} from query. Path: ${reqPath}`);
|
|
@@ -6453,7 +6732,7 @@ function createPluginRouteHandler(agents) {
|
|
|
6453
6732
|
return next();
|
|
6454
6733
|
}
|
|
6455
6734
|
}
|
|
6456
|
-
} else if (agentIdFromQuery && !
|
|
6735
|
+
} else if (agentIdFromQuery && !validateUuid23(agentIdFromQuery)) {
|
|
6457
6736
|
logger26.warn(`Invalid Agent ID format in query: ${agentIdFromQuery}. Path: ${reqPath}.`);
|
|
6458
6737
|
if (reqPath.startsWith("/api/")) {
|
|
6459
6738
|
res.status(400).json({
|
|
@@ -6483,7 +6762,7 @@ function createPluginRouteHandler(agents) {
|
|
|
6483
6762
|
};
|
|
6484
6763
|
}
|
|
6485
6764
|
function createApiRouter(agents, serverInstance) {
|
|
6486
|
-
const router =
|
|
6765
|
+
const router = express32.Router();
|
|
6487
6766
|
router.use(helmet({
|
|
6488
6767
|
contentSecurityPolicy: false,
|
|
6489
6768
|
crossOriginResourcePolicy: { policy: "cross-origin" },
|
|
@@ -6537,7 +6816,7 @@ import {
|
|
|
6537
6816
|
Service,
|
|
6538
6817
|
createUniqueUuid as createUniqueUuid6,
|
|
6539
6818
|
logger as logger28,
|
|
6540
|
-
validateUuid as
|
|
6819
|
+
validateUuid as validateUuid24
|
|
6541
6820
|
} from "@elizaos/core";
|
|
6542
6821
|
class MessageBusService extends Service {
|
|
6543
6822
|
static serviceType = "message-bus-service";
|
|
@@ -6594,7 +6873,7 @@ class MessageBusService extends Service {
|
|
|
6594
6873
|
const data = await response.json();
|
|
6595
6874
|
if (data.success && data.data?.channels && Array.isArray(data.data.channels)) {
|
|
6596
6875
|
data.data.channels.forEach((channel) => {
|
|
6597
|
-
if (channel.id &&
|
|
6876
|
+
if (channel.id && validateUuid24(channel.id)) {
|
|
6598
6877
|
this.validChannelIds.add(channel.id);
|
|
6599
6878
|
}
|
|
6600
6879
|
});
|
|
@@ -6615,7 +6894,7 @@ class MessageBusService extends Service {
|
|
|
6615
6894
|
async getChannelParticipants(channelId) {
|
|
6616
6895
|
try {
|
|
6617
6896
|
const serverApiUrl = this.getCentralMessageServerUrl();
|
|
6618
|
-
if (!
|
|
6897
|
+
if (!validateUuid24(channelId)) {
|
|
6619
6898
|
logger28.warn(`[${this.runtime.character.name}] MessageBusService: Invalid channel ID format: ${channelId}`);
|
|
6620
6899
|
return [];
|
|
6621
6900
|
}
|
|
@@ -7548,7 +7827,7 @@ class AgentServer {
|
|
|
7548
7827
|
if (options?.clientPath) {
|
|
7549
7828
|
this.clientPath = options.clientPath;
|
|
7550
7829
|
}
|
|
7551
|
-
this.app =
|
|
7830
|
+
this.app = express33();
|
|
7552
7831
|
const isProd = false;
|
|
7553
7832
|
logger30.debug("Setting up security headers...");
|
|
7554
7833
|
if (!isProd) {
|
|
@@ -7613,7 +7892,7 @@ class AgentServer {
|
|
|
7613
7892
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
7614
7893
|
allowedHeaders: ["Content-Type", "Authorization", "X-API-KEY"]
|
|
7615
7894
|
}));
|
|
7616
|
-
this.app.use(
|
|
7895
|
+
this.app.use(express33.json({
|
|
7617
7896
|
limit: process.env.EXPRESS_MAX_PAYLOAD || "2mb"
|
|
7618
7897
|
}));
|
|
7619
7898
|
const serverAuthToken = process.env.ELIZA_SERVER_AUTH_TOKEN;
|
|
@@ -7838,7 +8117,7 @@ class AgentServer {
|
|
|
7838
8117
|
}
|
|
7839
8118
|
if (clientPath) {
|
|
7840
8119
|
this.clientPath = clientPath;
|
|
7841
|
-
this.app.use(
|
|
8120
|
+
this.app.use(express33.static(clientPath, staticOptions));
|
|
7842
8121
|
logger30.info(`[STATIC] Serving static files from: ${clientPath}`);
|
|
7843
8122
|
} else {
|
|
7844
8123
|
logger30.warn("[STATIC] Client dist path not found. Searched locations:");
|