@stage5/lumine 0.2.49 → 0.2.50
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/lib/app-mcp/server.js +22 -4
- package/package.json +1 -1
package/lib/app-mcp/server.js
CHANGED
|
@@ -18,6 +18,22 @@ function delay(ms) {
|
|
|
18
18
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function rethrowAppMcpSessionError(error) {
|
|
22
|
+
const message = String(error?.message || error);
|
|
23
|
+
if (
|
|
24
|
+
Number(error?.status || 0) === 404 &&
|
|
25
|
+
/MCP session not found/i.test(message) &&
|
|
26
|
+
!/restart the Lumine app-mcp driver/i.test(message)
|
|
27
|
+
) {
|
|
28
|
+
const guided = new Error(
|
|
29
|
+
`${message}. Restart the Lumine app-mcp driver and reopen its new appUrl.`,
|
|
30
|
+
);
|
|
31
|
+
guided.status = error.status;
|
|
32
|
+
throw guided;
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
function openApp(url) {
|
|
22
38
|
const command =
|
|
23
39
|
process.platform === "darwin"
|
|
@@ -144,7 +160,7 @@ async function callAppTool({
|
|
|
144
160
|
sessionId,
|
|
145
161
|
name,
|
|
146
162
|
arguments: toolArguments,
|
|
147
|
-
});
|
|
163
|
+
}).catch(rethrowAppMcpSessionError);
|
|
148
164
|
const callId = created?.call?.id;
|
|
149
165
|
if (!callId) throw new Error("Twinkle did not create the app tool call.");
|
|
150
166
|
const deadline = Date.now() + CALL_TIMEOUT_MS;
|
|
@@ -155,7 +171,7 @@ async function callAppTool({
|
|
|
155
171
|
buildId,
|
|
156
172
|
sessionId,
|
|
157
173
|
callId,
|
|
158
|
-
});
|
|
174
|
+
}).catch(rethrowAppMcpSessionError);
|
|
159
175
|
const call = payload?.call;
|
|
160
176
|
if (call?.status === "completed") return call.result;
|
|
161
177
|
if (call?.status === "failed") {
|
|
@@ -169,14 +185,16 @@ async function callAppTool({
|
|
|
169
185
|
buildId,
|
|
170
186
|
sessionId,
|
|
171
187
|
callId,
|
|
172
|
-
});
|
|
188
|
+
}).catch(rethrowAppMcpSessionError);
|
|
173
189
|
if (finalPayload?.call?.status === "completed") {
|
|
174
190
|
return finalPayload.call.result;
|
|
175
191
|
}
|
|
176
192
|
if (finalPayload?.call?.status === "failed") {
|
|
177
193
|
throw new Error(finalPayload.call.errorMessage || "App tool failed.");
|
|
178
194
|
}
|
|
179
|
-
throw new Error(
|
|
195
|
+
throw new Error(
|
|
196
|
+
"App tool call timed out. Reload the appUrl tab, or restart the Lumine app-mcp driver and reopen its new appUrl.",
|
|
197
|
+
);
|
|
180
198
|
}
|
|
181
199
|
|
|
182
200
|
async function handleMcpMessage({ line, options, auth, buildId, session, tools }) {
|