@8btc/office-assistant-mcp 0.0.9 → 0.0.11

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/dist/index.cjs +67 -50
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -15,8 +15,8 @@ const index_js = require("@modelcontextprotocol/sdk/server/index.js");
15
15
  const types_js = require("@modelcontextprotocol/sdk/types.js");
16
16
  const ReactDOMServer = require("react-dom/server");
17
17
  const qrcode_react = require("qrcode.react");
18
- const zod = require("zod");
19
18
  const winston = require("winston");
19
+ const zod = require("zod");
20
20
  const zodToJsonSchema$1 = require("zod-to-json-schema");
21
21
  const fs = require("fs");
22
22
  const fsPromises = require("fs/promises");
@@ -74950,6 +74950,21 @@ const CodeBlock = ({ inline, className, children, ...props }) => {
74950
74950
  }
74951
74951
  ) }) : /* @__PURE__ */ jsxRuntime.jsx("code", { ...props, className, children });
74952
74952
  };
74953
+ const imgRegex = /!\[(.*?)\]\((.*?)\)/g;
74954
+ const windowsPattern = /[a-zA-Z]:(?:\\|\/)[^\s"'`<>|?*]*(?:[\\/][^\s"'`<>|?*]*)*/g;
74955
+ const replaceMarkdown = (mdContent) => {
74956
+ return mdContent.replaceAll(imgRegex, (m) => {
74957
+ let match = imgRegex.exec(m);
74958
+ let result = "";
74959
+ if (match) {
74960
+ const [, alt, src] = match;
74961
+ if (windowsPattern.test(src)) {
74962
+ result = `![${alt || ""}](${encodeURIComponent(src)})`;
74963
+ }
74964
+ }
74965
+ return result || m;
74966
+ });
74967
+ };
74953
74968
  const MarkdownRenderer = (props) => {
74954
74969
  const { markDownContent } = props;
74955
74970
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -74965,7 +74980,7 @@ const MarkdownRenderer = (props) => {
74965
74980
  ]
74966
74981
  ],
74967
74982
  components: { code: CodeBlock },
74968
- children: markDownContent || ""
74983
+ children: replaceMarkdown(markDownContent || "")
74969
74984
  }
74970
74985
  );
74971
74986
  };
@@ -76821,6 +76836,37 @@ const renderFullHtml = (segment) => {
76821
76836
  `;
76822
76837
  };
76823
76838
  const getQrcodeUrl = () => process$1.env.QRCODE_URL || "https://reactjs.org/";
76839
+ const logger = winston.createLogger({
76840
+ level: "info",
76841
+ format: winston.format.json(),
76842
+ defaultMeta: { service: "user-service" },
76843
+ transports: [
76844
+ //
76845
+ // - Write all logs with importance level of `error` or higher to `error.log`
76846
+ // (i.e., error, fatal, but not other levels)
76847
+ //
76848
+ new winston.transports.File({
76849
+ dirname: "logs",
76850
+ filename: "office.loggererror.log",
76851
+ level: "error"
76852
+ }),
76853
+ //
76854
+ // - Write all logs with importance level of `info` or higher to `combined.log`
76855
+ // (i.e., fatal, error, warn, and info, but not trace)
76856
+ //
76857
+ new winston.transports.File({
76858
+ dirname: "logs",
76859
+ filename: "office.logercombined.log"
76860
+ })
76861
+ ]
76862
+ });
76863
+ if (process.env.NODE_ENV !== "production") {
76864
+ logger.add(
76865
+ new winston.transports.Console({
76866
+ format: winston.format.simple()
76867
+ })
76868
+ );
76869
+ }
76824
76870
  async function generateBasePdf(data) {
76825
76871
  return [
76826
76872
  {
@@ -76851,6 +76897,7 @@ const renderCover = (data) => {
76851
76897
  };
76852
76898
  const renderSegment = (data) => {
76853
76899
  const html2 = ReactDOMServer.renderToString(/* @__PURE__ */ jsxRuntime.jsx(Segment, { data }));
76900
+ logger.error(html2);
76854
76901
  return renderFullHtml(html2);
76855
76902
  };
76856
76903
  const renderEnd = (data) => {
@@ -76883,37 +76930,6 @@ const basePdfSchema = {
76883
76930
  zod.z.object({
76884
76931
  ...basePdfSchema
76885
76932
  });
76886
- const logger = winston.createLogger({
76887
- level: "info",
76888
- format: winston.format.json(),
76889
- defaultMeta: { service: "user-service" },
76890
- transports: [
76891
- //
76892
- // - Write all logs with importance level of `error` or higher to `error.log`
76893
- // (i.e., error, fatal, but not other levels)
76894
- //
76895
- new winston.transports.File({
76896
- dirname: "logs",
76897
- filename: "office.loggererror.log",
76898
- level: "error"
76899
- }),
76900
- //
76901
- // - Write all logs with importance level of `info` or higher to `combined.log`
76902
- // (i.e., fatal, error, warn, and info, but not trace)
76903
- //
76904
- new winston.transports.File({
76905
- dirname: "logs",
76906
- filename: "office.logercombined.log"
76907
- })
76908
- ]
76909
- });
76910
- if (process.env.NODE_ENV !== "production") {
76911
- logger.add(
76912
- new winston.transports.Console({
76913
- format: winston.format.simple()
76914
- })
76915
- );
76916
- }
76917
76933
  const zodToJsonSchema = (schema) => {
76918
76934
  return zodToJsonSchema$1.zodToJsonSchema(zod.z.object(schema), {
76919
76935
  rejectedAdditionalProperties: void 0,
@@ -77007,13 +77023,18 @@ const extractAllImageSrc = (html2) => {
77007
77023
  logger.info("extractAllImageSrc match[0]:" + match[0], match[1]);
77008
77024
  logger.info("extractAllImageSrc match[1]:" + match[1]);
77009
77025
  }
77010
- if (isLocalPath(match[1])) {
77011
- srcs.push(match[1]);
77026
+ const decodedSrc = decodeURIComponent(match[1]);
77027
+ if (isLocalPath(decodedSrc)) {
77028
+ srcs.push({
77029
+ src: decodedSrc,
77030
+ originSrc: match[1]
77031
+ });
77012
77032
  }
77013
77033
  }
77014
77034
  return srcs;
77015
77035
  };
77016
77036
  const reg = /<img[^>]+>/gi;
77037
+ const regByGroup = /(<img[^>]*?)src=["'][^"']*["']([^>]*>)/gi;
77017
77038
  const createPage = async (page, item) => {
77018
77039
  const {
77019
77040
  tempFileName,
@@ -77031,12 +77052,15 @@ const createPage = async (page, item) => {
77031
77052
  </header>
77032
77053
  `;
77033
77054
  const localSrcs = extractAllImageSrc(html2);
77034
- logger.info("localSrcs:::" + localSrcs.join(","));
77035
77055
  const localFileInfoList = await Promise.all(
77036
77056
  localSrcs.map(
77037
- (src) => new Promise((resolve) => {
77038
- localImageToBase64(src).then((fileInfo) => {
77039
- resolve(fileInfo);
77057
+ (srcInfo) => new Promise((resolve) => {
77058
+ localImageToBase64(srcInfo.src).then((fileInfo) => {
77059
+ resolve({
77060
+ ...fileInfo,
77061
+ // 原本没转换的地址
77062
+ originSrc: srcInfo.originSrc
77063
+ });
77040
77064
  }).catch(() => {
77041
77065
  resolve("");
77042
77066
  });
@@ -77044,14 +77068,11 @@ const createPage = async (page, item) => {
77044
77068
  )
77045
77069
  );
77046
77070
  const _html = html2.replaceAll(reg, (m) => {
77047
- const item2 = localFileInfoList.find(
77048
- (info) => m.indexOf(info.src) !== -1
77049
- );
77071
+ const item2 = localFileInfoList.find((info) => {
77072
+ return m.indexOf(info?.originSrc || "") !== -1;
77073
+ });
77050
77074
  if (item2) {
77051
- return m.replace(
77052
- /(<img[^>]*?)src=["'][^"']*["']([^>]*>)/gi,
77053
- `$1src="${item2.base64}"$2`
77054
- );
77075
+ return m.replace(regByGroup, `$1src="${item2.base64}"$2`);
77055
77076
  }
77056
77077
  return m;
77057
77078
  });
@@ -77236,10 +77257,6 @@ const tool = {
77236
77257
  const toolHandler = async (args) => {
77237
77258
  try {
77238
77259
  logger.info(`start: ${(/* @__PURE__ */ new Date()).getTime()}`);
77239
- try {
77240
- logger.info(JSON.stringify(args));
77241
- } catch (e) {
77242
- }
77243
77260
  const generatedTemplates = await generateBasePdf(args);
77244
77261
  const pdfUrl = await generatePDF({
77245
77262
  list: generatedTemplates,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@8btc/office-assistant-mcp",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "办公agent辅助mcp工具",
5
5
  "main": "dist/index.cjs",
6
6
  "type": "module",