@kuluomi/mapp-router-mcp 0.3.4 → 0.3.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/server.mjs +38 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuluomi/mapp-router-mcp",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "MAPP 平台意图路由 MCP 服务:列出可转交的应用,并把任务转交给它们。单文件、零运行时依赖。",
5
5
  "type": "module",
6
6
  "bin": {
package/server.mjs CHANGED
@@ -29532,7 +29532,7 @@ var DEFAULT_EXCLUDE_IDS = ["48621dce-c1df-4e1d-b6a4-be12f2ddcad3"];
29532
29532
  for (const id of DEFAULT_EXCLUDE_IDS) EXCLUDE_IDS.add(id);
29533
29533
  var BOOT_ID = randomUUID().slice(0, 8);
29534
29534
  var STARTED_AT = (/* @__PURE__ */ new Date()).toISOString();
29535
- var SERVER_VERSION = "0.3.4";
29535
+ var SERVER_VERSION = "0.3.5";
29536
29536
  function cwdPeek(limit = 8) {
29537
29537
  try {
29538
29538
  const names = readdirSync(process.cwd()).filter((n) => !n.startsWith("."));
@@ -29612,6 +29612,10 @@ async function uploadFileToApp({ appId, uid, filePath }) {
29612
29612
  }
29613
29613
  var callCount = 0;
29614
29614
  var recentCalls = [];
29615
+ var runningByKey = /* @__PURE__ */ new Map();
29616
+ function taskKeyOf(appId, sessionId, message, filePaths) {
29617
+ return [appId, sessionId ?? "", message, (filePaths ?? []).join("|")].join("\0");
29618
+ }
29615
29619
  function log(...args) {
29616
29620
  console.error(`[${(/* @__PURE__ */ new Date()).toISOString()}]`, ...args);
29617
29621
  }
@@ -29892,10 +29896,11 @@ function pruneTasks() {
29892
29896
  }
29893
29897
  }
29894
29898
  }
29895
- function startTask(hit, message, sessionId) {
29899
+ function startTask(hit, message, sessionId, dedupeKey = "") {
29896
29900
  const id = `t_${randomUUID().slice(0, 8)}`;
29897
29901
  const task = {
29898
29902
  id,
29903
+ key: dedupeKey,
29899
29904
  app_name: hit.name,
29900
29905
  app_id: hit.id,
29901
29906
  agent_type: hit.agent_type,
@@ -29909,10 +29914,15 @@ function startTask(hit, message, sessionId) {
29909
29914
  error: ""
29910
29915
  };
29911
29916
  tasks.set(id, task);
29917
+ if (dedupeKey) runningByKey.set(dedupeKey, task);
29912
29918
  pruneTasks();
29913
29919
  log(`task ${id} \u2192 ${hit.name}(${hit.agent_type}) session=${sessionId || "\u65B0\u4F1A\u8BDD"}`);
29920
+ const releaseKey = () => {
29921
+ if (task.key && runningByKey.get(task.key) === task) runningByKey.delete(task.key);
29922
+ };
29914
29923
  executeRun(hit, message, sessionId).then((r) => {
29915
29924
  task.finished_ms = Date.now();
29925
+ releaseKey();
29916
29926
  if (r.ok) {
29917
29927
  task.status = "done";
29918
29928
  task.result = r;
@@ -29928,6 +29938,7 @@ function startTask(hit, message, sessionId) {
29928
29938
  }
29929
29939
  }).catch((e) => {
29930
29940
  task.finished_ms = Date.now();
29941
+ releaseKey();
29931
29942
  task.status = "failed";
29932
29943
  task.error = e?.name === "TimeoutError" ? `\u5B50\u667A\u80FD\u4F53\u8D85\u8FC7 ${RUN_TIMEOUT_MS / 1e3}s \u672A\u8FD4\u56DE` : e?.message ?? String(e);
29933
29944
  log(`task ${id} ERROR: ${task.error}`);
@@ -29989,12 +30000,16 @@ function createMcpServer() {
29989
30000
  "mcp_probe",
29990
30001
  {
29991
30002
  title: "\u8FDE\u901A\u6027\u63A2\u9488",
29992
- description: "\u56DE\u663E\u672C MCP \u670D\u52A1\u7684\u8FD0\u884C\u8EAB\u4EFD\uFF08\u4E3B\u673A\u3001\u7AEF\u53E3\u3001\u542F\u52A8\u65F6\u95F4\u3001\u88AB\u8C03\u7528\u6B21\u6570\uFF09\u3002\u7528\u4E8E\u9A8C\u8BC1\u5E73\u53F0\u4FA7\u8FD0\u884C\u65F6\u80FD\u5426\u771F\u6B63\u8FDE\u5230\u672C\u670D\u52A1\uFF0C\u4E0D\u6D89\u53CA\u4EFB\u4F55\u4E1A\u52A1\u3002",
29993
- inputSchema: { note: external_exports.string().describe("\u4EFB\u610F\u6587\u672C\uFF0C\u4F1A\u539F\u6837\u56DE\u663E").optional() }
30003
+ description: "\u56DE\u663E\u672C MCP \u670D\u52A1\u7684\u8FD0\u884C\u8EAB\u4EFD\uFF08\u4E3B\u673A\u3001\u7AEF\u53E3\u3001\u542F\u52A8\u65F6\u95F4\u3001\u88AB\u8C03\u7528\u6B21\u6570\uFF09\u3002\u7528\u4E8E\u9A8C\u8BC1\u5E73\u53F0\u4FA7\u8FD0\u884C\u65F6\u80FD\u5426\u771F\u6B63\u8FDE\u5230\u672C\u670D\u52A1\uFF0C\u4E0D\u6D89\u53CA\u4EFB\u4F55\u4E1A\u52A1\u3002\u5E26 sleep_ms \u65F6\u5148\u539F\u5730\u7B49\u8FD9\u4E48\u591A\u6BEB\u79D2\u518D\u56DE\uFF1A\u4E13\u95E8\u7528\u6765\u91CF\u5E73\u53F0\u5355\u6B21\u5DE5\u5177\u8C03\u7528\u7684\u771F\u5B9E\u4E0A\u9650\uFF08\u4E0D\u63D0\u4EA4\u4EFB\u4F55\u4EFB\u52A1\uFF0C\u6390\u65AD\u4E5F\u6CA1\u6709\u526F\u4F5C\u7528\uFF09\u3002",
30004
+ inputSchema: {
30005
+ note: external_exports.string().describe("\u4EFB\u610F\u6587\u672C\uFF0C\u4F1A\u539F\u6837\u56DE\u663E").optional(),
30006
+ sleep_ms: external_exports.number().int().min(1).max(6e4).describe("\u5148\u7B49 N \u6BEB\u79D2\u518D\u56DE\uFF0C\u7528\u6765\u6D4B\u5E73\u53F0\u5355\u6B21\u5DE5\u5177\u8C03\u7528\u7684\u8D85\u65F6\u4E0A\u9650").optional()
30007
+ }
29994
30008
  },
29995
- async ({ note }) => {
30009
+ async ({ note, sleep_ms }) => {
29996
30010
  callCount += 1;
29997
- recentCalls.push(`mcp_probe${note ? `(${note})` : ""}`);
30011
+ recentCalls.push(`mcp_probe${note ? `(${note})` : ""}${sleep_ms ? `+${sleep_ms}ms` : ""}`);
30012
+ if (sleep_ms) await new Promise((r) => setTimeout(r, Math.min(6e4, Math.max(1, sleep_ms))));
29998
30013
  const text = [
29999
30014
  "MCP \u901A\u9053\u8FDE\u901A\u3002\u4EE5\u4E0B\u4E3A\u670D\u52A1\u7AEF\u4FE1\u606F\uFF1A",
30000
30015
  /**
@@ -30120,6 +30135,22 @@ function createMcpServer() {
30120
30135
  true
30121
30136
  );
30122
30137
  }
30138
+ const dedupeKey = taskKeyOf(app_id, session_id, message, file_paths);
30139
+ const existing = runningByKey.get(dedupeKey);
30140
+ if (existing) {
30141
+ log(`run_app dedupe hit \u2192 ${existing.id}`);
30142
+ const done2 = await waitForTask(existing, RUN_INLINE_WAIT_MS);
30143
+ if (!done2) {
30144
+ return textContent(
30145
+ `${renderPending(existing)}
30146
+ \uFF08\u540C\u4E00\u4E2A\u8BF7\u6C42\u6B63\u5728\u6267\u884C\uFF0C\u5DF2\u5408\u5E76\u5230 task_id=${existing.id}\uFF0C\u6CA1\u6709\u91CD\u65B0\u63D0\u4EA4\uFF09`
30147
+ );
30148
+ }
30149
+ if (existing.status === "failed") {
30150
+ return textContent(`\u8C03\u7528\u300C${existing.app_name}\u300D\u5931\u8D25\uFF1A${existing.error}`, true);
30151
+ }
30152
+ return textContent(renderDone(existing));
30153
+ }
30123
30154
  let finalMessage = message;
30124
30155
  if (Array.isArray(file_paths) && file_paths.length > 0) {
30125
30156
  const uid = (hit.uid ?? "").trim() || processUid();
@@ -30153,7 +30184,7 @@ function createMcpServer() {
30153
30184
 
30154
30185
  ` + message;
30155
30186
  }
30156
- const task = startTask(hit, finalMessage, session_id);
30187
+ const task = startTask(hit, finalMessage, session_id, dedupeKey);
30157
30188
  const done = await waitForTask(task, RUN_INLINE_WAIT_MS);
30158
30189
  if (!done) return textContent(renderPending(task));
30159
30190
  if (task.status === "failed") {