mslxdff 0.1.6 → 0.1.8

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/bin/mslxdff.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { execFile } from "node:child_process";
3
- import { readFileSync, existsSync, statSync, watch, openSync } from "node:fs";
3
+ import { readFileSync, existsSync, statSync, watch, openSync, closeSync, mkdirSync } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
5
- import { dirname, join } from "node:path";
5
+ import { dirname, join, basename } from "node:path";
6
6
  import { startServer, resolvePort } from "../src/server.js";
7
7
  import { createRouter } from "../src/routes.js";
8
8
  import { createUpstreamClient } from "../src/upstream.js";
@@ -662,7 +662,7 @@ function fmtEvent(e) {
662
662
  const m = (x) => x || "-";
663
663
  switch (e?.type) {
664
664
  case "request":
665
- return `${head} request ${m(e.model)}${e.auto ? " (auto)" : ""} hops=${e.hops} from ${e.ip || "?"}${e.stream ? " stream" : ""}`;
665
+ return `${head} request ${m(e.model)}${e.auto ? " (auto)" : ""} hops=${e.hops} from ${e.ip || "?"}${e.stream ? " stream" : ""}${e.prompt ? ` content="${e.prompt}"` : ""}`;
666
666
  case "upstream-error":
667
667
  return `${head} upstream err ${m(e.model)} ${e.status ? `HTTP ${e.status}` : "network"}: ${m(e.message)}`;
668
668
  case "peer-health":
@@ -685,7 +685,8 @@ async function liveDebug() {
685
685
  // ensure the event file exists so watch() doesn't fail on a fresh daemon dir
686
686
  if (!existsSync(file)) {
687
687
  try {
688
- openSync(file, "a").close();
688
+ mkdirSync(dirname(file), { recursive: true });
689
+ closeSync(openSync(file, "a"));
689
690
  } catch {
690
691
  console.error(`cannot create event file: ${file}`);
691
692
  process.exit(1);
@@ -727,11 +728,18 @@ async function liveDebug() {
727
728
  }
728
729
  };
729
730
  try {
730
- watch(file, { persistent: true }, pump);
731
+ mkdirSync(dirname(file), { recursive: true });
732
+ watch(dirname(file), (_evt, filename) => {
733
+ if (!filename || basename(String(filename)) !== basename(file)) return;
734
+ pump();
735
+ });
731
736
  } catch {
732
- console.error(`cannot watch event file: ${file}`);
737
+ console.error(`cannot watch event dir: ${dirname(file)}`);
733
738
  process.exit(1);
734
739
  }
740
+ // fs.watch is unreliable for freshly-created files on Windows — poll as a
741
+ // safety net so events are never missed.
742
+ setInterval(pump, 250);
735
743
  pump();
736
744
  await new Promise(() => {}); // run until Ctrl+C
737
745
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mslxdff",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "测试项目,请勿使用。",
5
5
  "type": "module",
6
6
  "bin": {
package/src/routes.js CHANGED
@@ -117,6 +117,26 @@ export async function peerHealthyModels(peer, { timeoutMs = PEER_STATUS_TIMEOUT_
117
117
  }
118
118
  }
119
119
 
120
+ export const PROMPT_MAX_LEN = 160;
121
+
122
+ // Human-debuggable summary of the request body: the last non-empty message
123
+ // text (multi-modal parts joined), whitespace-flattened and truncated.
124
+ export function summarizePrompt(body) {
125
+ const msgs = body?.messages;
126
+ if (!Array.isArray(msgs) || !msgs.length) return "";
127
+ const msg = msgs[msgs.length - 1];
128
+ const c = msg?.content;
129
+ let text = "";
130
+ if (typeof c === "string") text = c;
131
+ else if (Array.isArray(c)) {
132
+ text = c
133
+ .map((p) => (typeof p === "string" ? p : p && typeof p.text === "string" ? p.text : ""))
134
+ .join(" ");
135
+ }
136
+ text = String(text || "").replace(/\s+/g, " ").trim();
137
+ return text.length > PROMPT_MAX_LEN ? text.slice(0, PROMPT_MAX_LEN) + "…" : text;
138
+ }
139
+
120
140
  function parseHops(header) {
121
141
  const n = Number(header);
122
142
  return Number.isInteger(n) && n >= 0 ? n : 0;
@@ -186,7 +206,7 @@ const ROUTES = [
186
206
  const logError = (model, status, message) =>
187
207
  logs?.appendError({ model, auto: useAuto, status, message });
188
208
  const evt = (type, data) => logs?.appendEvent?.({ type, ...data, model: data.model ?? requested, auto: useAuto, durationMs: Date.now() - startedAt });
189
- evt("request", { hops, ip: clientIp(req), stream: Boolean(body.stream) });
209
+ evt("request", { hops, ip: clientIp(req), stream: Boolean(body.stream), prompt: summarizePrompt(body) });
190
210
 
191
211
  let lastErr = null;
192
212
  for (const model of order) {