mercury-agent 0.5.15 → 0.5.16
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/package.json +1 -1
- package/src/cli/mercury.ts +9 -0
- package/src/core/routes/chat.ts +43 -1
package/package.json
CHANGED
package/src/cli/mercury.ts
CHANGED
|
@@ -1940,6 +1940,10 @@ program
|
|
|
1940
1940
|
.option("-s, --space <spaceId>", "Space to route the message to", "main")
|
|
1941
1941
|
.option("-f, --file <paths...>", "Attach files to the message")
|
|
1942
1942
|
.option("--caller <callerId>", "Caller ID", "cli:user")
|
|
1943
|
+
.option(
|
|
1944
|
+
"--platform <platform>",
|
|
1945
|
+
"Simulate platform for DM auto-space resolution (e.g. whatsapp)",
|
|
1946
|
+
)
|
|
1943
1947
|
.option("--json", "Output raw JSON response")
|
|
1944
1948
|
.action(
|
|
1945
1949
|
async (
|
|
@@ -1949,6 +1953,7 @@ program
|
|
|
1949
1953
|
space: string;
|
|
1950
1954
|
file?: string[];
|
|
1951
1955
|
caller: string;
|
|
1956
|
+
platform?: string;
|
|
1952
1957
|
json?: boolean;
|
|
1953
1958
|
},
|
|
1954
1959
|
) => {
|
|
@@ -1975,6 +1980,10 @@ program
|
|
|
1975
1980
|
spaceId: options.space,
|
|
1976
1981
|
};
|
|
1977
1982
|
|
|
1983
|
+
if (options.platform) {
|
|
1984
|
+
body.platform = options.platform;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1978
1987
|
if (options.file && options.file.length > 0) {
|
|
1979
1988
|
const files: Array<{ name: string; data: string }> = [];
|
|
1980
1989
|
for (const filePath of options.file) {
|
package/src/core/routes/chat.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Hono } from "hono";
|
|
|
5
5
|
import { logger } from "../../logger.js";
|
|
6
6
|
import { ensureSpaceWorkspace } from "../../storage/memory.js";
|
|
7
7
|
import type { IngressMessage, MessageAttachment } from "../../types.js";
|
|
8
|
+
import { type AutoSpaceConfig, resolveConversation } from "../conversation.js";
|
|
8
9
|
import { extToMime, mimeToMediaType } from "../media.js";
|
|
9
10
|
import type { MercuryCoreRuntime } from "../runtime.js";
|
|
10
11
|
import { isOverQuota } from "../storage-guard.js";
|
|
@@ -54,7 +55,7 @@ export function createChatRoute(core: MercuryCoreRuntime): Hono {
|
|
|
54
55
|
? body.callerId.trim()
|
|
55
56
|
: "api:anonymous";
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
let spaceId =
|
|
58
59
|
typeof body.spaceId === "string" && body.spaceId.trim()
|
|
59
60
|
? body.spaceId.trim()
|
|
60
61
|
: "main";
|
|
@@ -62,6 +63,44 @@ export function createChatRoute(core: MercuryCoreRuntime): Hono {
|
|
|
62
63
|
const authorName =
|
|
63
64
|
typeof body.authorName === "string" ? body.authorName.trim() : undefined;
|
|
64
65
|
|
|
66
|
+
const platform =
|
|
67
|
+
typeof body.platform === "string" && body.platform.trim()
|
|
68
|
+
? body.platform.trim()
|
|
69
|
+
: undefined;
|
|
70
|
+
|
|
71
|
+
if (platform && platform !== "api") {
|
|
72
|
+
const autoSpaceConfig: AutoSpaceConfig | undefined = core.config
|
|
73
|
+
.dmAutoSpaceEnabled
|
|
74
|
+
? {
|
|
75
|
+
enabled: true,
|
|
76
|
+
adminIds: core.config.dmAutoSpaceAdminIds
|
|
77
|
+
.split(",")
|
|
78
|
+
.map((s) => s.trim())
|
|
79
|
+
.filter(Boolean),
|
|
80
|
+
defaultSystemPrompt: core.config.dmAutoSpaceDefaultSystemPrompt,
|
|
81
|
+
defaultMemberPermissions:
|
|
82
|
+
core.config.dmAutoSpaceDefaultMemberPermissions,
|
|
83
|
+
rateLimitDailyMember: core.config.rateLimitDailyMember,
|
|
84
|
+
}
|
|
85
|
+
: undefined;
|
|
86
|
+
|
|
87
|
+
const resolution = resolveConversation(
|
|
88
|
+
core.db,
|
|
89
|
+
platform,
|
|
90
|
+
callerId,
|
|
91
|
+
"dm",
|
|
92
|
+
undefined,
|
|
93
|
+
autoSpaceConfig,
|
|
94
|
+
authorName,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
if (!resolution) {
|
|
98
|
+
return c.json({ error: "Conversation not linked to any space" }, 404);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
spaceId = resolution.spaceId;
|
|
102
|
+
}
|
|
103
|
+
|
|
65
104
|
if (!core.db.getSpace(spaceId)) {
|
|
66
105
|
return c.json({ error: "Space not found" }, 404);
|
|
67
106
|
}
|
|
@@ -126,6 +165,9 @@ export function createChatRoute(core: MercuryCoreRuntime): Hono {
|
|
|
126
165
|
logger.info("API chat inbound", {
|
|
127
166
|
callerId,
|
|
128
167
|
spaceId,
|
|
168
|
+
...(platform && platform !== "api"
|
|
169
|
+
? { simulatedPlatform: platform }
|
|
170
|
+
: {}),
|
|
129
171
|
preview: ingress.text.slice(0, 80),
|
|
130
172
|
fileCount: attachments.length,
|
|
131
173
|
});
|