@mobcode/openclaw-plugin 0.1.18 → 0.1.19
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/gateway-methods.js +40 -12
package/package.json
CHANGED
package/src/gateway-methods.js
CHANGED
|
@@ -5,6 +5,30 @@ export function registerMobcodeGatewayMethods({
|
|
|
5
5
|
pluginMetadata,
|
|
6
6
|
api,
|
|
7
7
|
}) {
|
|
8
|
+
const respondInvalid = (respond, message, details) => {
|
|
9
|
+
respond(
|
|
10
|
+
false,
|
|
11
|
+
undefined,
|
|
12
|
+
{
|
|
13
|
+
code: "INVALID_REQUEST",
|
|
14
|
+
message,
|
|
15
|
+
...(details !== undefined ? { details } : {}),
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const respondUnavailable = (respond, message, details) => {
|
|
21
|
+
respond(
|
|
22
|
+
false,
|
|
23
|
+
undefined,
|
|
24
|
+
{
|
|
25
|
+
code: "UNAVAILABLE",
|
|
26
|
+
message,
|
|
27
|
+
...(details !== undefined ? { details } : {}),
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
8
32
|
api.registerGatewayMethod("mobcode.capabilities", async ({ respond }) => {
|
|
9
33
|
respond(true, {
|
|
10
34
|
ok: true,
|
|
@@ -31,7 +55,7 @@ export function registerMobcodeGatewayMethods({
|
|
|
31
55
|
api.registerGatewayMethod("mobcode.provider.models.list", async ({ params, respond }) => {
|
|
32
56
|
const providerId = typeof params?.providerId === "string" ? params.providerId.trim() : "";
|
|
33
57
|
if (!providerId) {
|
|
34
|
-
respond
|
|
58
|
+
respondInvalid(respond, "providerId required");
|
|
35
59
|
return;
|
|
36
60
|
}
|
|
37
61
|
const payload = await builders.providerModels(providerId);
|
|
@@ -44,7 +68,7 @@ export function registerMobcodeGatewayMethods({
|
|
|
44
68
|
api.registerGatewayMethod("mobcode.messages.page", async ({ params, respond }) => {
|
|
45
69
|
const sessionKey = typeof params?.sessionKey === "string" ? params.sessionKey.trim() : "";
|
|
46
70
|
if (!sessionKey) {
|
|
47
|
-
respond
|
|
71
|
+
respondInvalid(respond, "sessionKey required");
|
|
48
72
|
return;
|
|
49
73
|
}
|
|
50
74
|
api.logger?.info?.(
|
|
@@ -84,12 +108,12 @@ export function registerMobcodeGatewayMethods({
|
|
|
84
108
|
api.registerGatewayMethod("mobcode.artifacts.get", async ({ params, respond }) => {
|
|
85
109
|
const artifactId = typeof params?.artifactId === "string" ? params.artifactId.trim() : "";
|
|
86
110
|
if (!artifactId) {
|
|
87
|
-
respond
|
|
111
|
+
respondInvalid(respond, "artifactId required");
|
|
88
112
|
return;
|
|
89
113
|
}
|
|
90
114
|
const artifact = await store.readArtifactById(artifactId);
|
|
91
115
|
if (!artifact?.document) {
|
|
92
|
-
respond
|
|
116
|
+
respondInvalid(respond, "artifact not found");
|
|
93
117
|
return;
|
|
94
118
|
}
|
|
95
119
|
respond(true, {
|
|
@@ -107,12 +131,12 @@ export function registerMobcodeGatewayMethods({
|
|
|
107
131
|
api.registerGatewayMethod("mobcode.artifacts.resolveBlob", async ({ params, respond }) => {
|
|
108
132
|
const blobId = typeof params?.blobId === "string" ? params.blobId.trim() : "";
|
|
109
133
|
if (!blobId) {
|
|
110
|
-
respond
|
|
134
|
+
respondInvalid(respond, "blobId required");
|
|
111
135
|
return;
|
|
112
136
|
}
|
|
113
137
|
const path = await store.resolveArtifactBlobPath(blobId);
|
|
114
138
|
if (!path) {
|
|
115
|
-
respond
|
|
139
|
+
respondInvalid(respond, "blob not found");
|
|
116
140
|
return;
|
|
117
141
|
}
|
|
118
142
|
respond(true, {
|
|
@@ -126,7 +150,7 @@ export function registerMobcodeGatewayMethods({
|
|
|
126
150
|
const sessionKey = typeof params?.sessionKey === "string" ? params.sessionKey.trim() : "";
|
|
127
151
|
const toolCallId = typeof params?.toolCallId === "string" ? params.toolCallId.trim() : "";
|
|
128
152
|
if (!sessionKey || !toolCallId) {
|
|
129
|
-
respond
|
|
153
|
+
respondInvalid(respond, "sessionKey and toolCallId are required");
|
|
130
154
|
return;
|
|
131
155
|
}
|
|
132
156
|
const timeoutMs =
|
|
@@ -139,7 +163,11 @@ export function registerMobcodeGatewayMethods({
|
|
|
139
163
|
timeoutMs,
|
|
140
164
|
});
|
|
141
165
|
if (!result?.message) {
|
|
142
|
-
respond
|
|
166
|
+
respondUnavailable(respond, "tool result not found", {
|
|
167
|
+
sessionKey,
|
|
168
|
+
toolCallId,
|
|
169
|
+
timeoutMs,
|
|
170
|
+
});
|
|
143
171
|
return;
|
|
144
172
|
}
|
|
145
173
|
respond(true, {
|
|
@@ -154,7 +182,7 @@ export function registerMobcodeGatewayMethods({
|
|
|
154
182
|
api.registerGatewayMethod("mobcode.client.register", async ({ params, respond }) => {
|
|
155
183
|
const clientId = typeof params?.clientId === "string" ? params.clientId.trim() : "";
|
|
156
184
|
if (!clientId) {
|
|
157
|
-
respond
|
|
185
|
+
respondInvalid(respond, "clientId required");
|
|
158
186
|
return;
|
|
159
187
|
}
|
|
160
188
|
const result = await store.registerClientSession({
|
|
@@ -175,7 +203,7 @@ export function registerMobcodeGatewayMethods({
|
|
|
175
203
|
api.registerGatewayMethod("mobcode.client.actions.poll", async ({ params, respond }) => {
|
|
176
204
|
const clientId = typeof params?.clientId === "string" ? params.clientId.trim() : "";
|
|
177
205
|
if (!clientId) {
|
|
178
|
-
respond
|
|
206
|
+
respondInvalid(respond, "clientId required");
|
|
179
207
|
return;
|
|
180
208
|
}
|
|
181
209
|
const actions = await store.pollClientActions(clientId, {
|
|
@@ -190,7 +218,7 @@ export function registerMobcodeGatewayMethods({
|
|
|
190
218
|
api.registerGatewayMethod("mobcode.client.actions.wait", async ({ params, respond }) => {
|
|
191
219
|
const clientId = typeof params?.clientId === "string" ? params.clientId.trim() : "";
|
|
192
220
|
if (!clientId) {
|
|
193
|
-
respond
|
|
221
|
+
respondInvalid(respond, "clientId required");
|
|
194
222
|
return;
|
|
195
223
|
}
|
|
196
224
|
const action = await store.waitForClientAction(clientId, {
|
|
@@ -207,7 +235,7 @@ export function registerMobcodeGatewayMethods({
|
|
|
207
235
|
const actionId = typeof params?.actionId === "string" ? params.actionId.trim() : "";
|
|
208
236
|
const status = typeof params?.status === "string" ? params.status.trim() : "";
|
|
209
237
|
if (!clientId || !actionId || !status) {
|
|
210
|
-
respond
|
|
238
|
+
respondInvalid(respond, "clientId, actionId, and status are required");
|
|
211
239
|
return;
|
|
212
240
|
}
|
|
213
241
|
respond(true, {
|