imean-service-engine 1.6.0 → 1.7.1

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/dist/mod.cjs CHANGED
@@ -7,6 +7,7 @@ var nodeServer = require('@hono/node-server');
7
7
  var etcd3 = require('etcd3');
8
8
  var fs = require('fs-extra');
9
9
  var hono = require('hono');
10
+ var timing = require('hono/timing');
10
11
  var api = require('@opentelemetry/api');
11
12
  var winston = require('winston');
12
13
  var prettier = require('prettier');
@@ -17,6 +18,8 @@ var mcp_js = require('@modelcontextprotocol/sdk/server/mcp.js');
17
18
  var types_js = require('@modelcontextprotocol/sdk/types.js');
18
19
  var streaming = require('hono/streaming');
19
20
  var ulid = require('ulid');
21
+ var html = require('hono/html');
22
+ var jsxRuntime = require('hono/jsx/jsx-runtime');
20
23
  var dayjs = require('dayjs');
21
24
 
22
25
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -595,6 +598,62 @@ var ActionHandler = class {
595
598
  function isAsyncIterable(obj) {
596
599
  return obj != null && typeof obj[Symbol.asyncIterator] === "function";
597
600
  }
601
+
602
+ // decorators/page.ts
603
+ var PAGE_METADATA = Symbol("page:metadata");
604
+ function Page(options) {
605
+ return function(_target, context) {
606
+ const methodName = context.name;
607
+ context.addInitializer(function() {
608
+ const prototype = this.constructor.prototype;
609
+ const existingMetadata = prototype[PAGE_METADATA] || {};
610
+ existingMetadata[methodName] = {
611
+ name: methodName,
612
+ description: options.description || "",
613
+ method: options.method,
614
+ path: options.path
615
+ };
616
+ prototype[PAGE_METADATA] = existingMetadata;
617
+ });
618
+ };
619
+ }
620
+ function getPageMetadata(target) {
621
+ return target.constructor.prototype[PAGE_METADATA] ?? {};
622
+ }
623
+ var tracer3 = api.trace.getTracer("page-handler");
624
+ var PageHandler = class {
625
+ constructor(moduleInstance, options, moduleName) {
626
+ this.moduleInstance = moduleInstance;
627
+ this.options = options;
628
+ this.moduleName = moduleName;
629
+ }
630
+ async handle(ctx) {
631
+ return await tracer3.startActiveSpan(
632
+ `handle ${this.moduleName}.${this.options.name}`,
633
+ async (span) => {
634
+ span.setAttribute("module", this.moduleName);
635
+ span.setAttribute("page", this.options.name);
636
+ span.setAttribute("path", this.options.path);
637
+ try {
638
+ const result = await this.moduleInstance[this.options.name].apply(
639
+ this.moduleInstance,
640
+ [ctx]
641
+ );
642
+ return ctx.html(result);
643
+ } catch (error) {
644
+ span.recordException(error);
645
+ span.setStatus({
646
+ code: api.SpanStatusCode.ERROR,
647
+ message: error.message
648
+ });
649
+ throw error;
650
+ } finally {
651
+ span.end();
652
+ }
653
+ }
654
+ );
655
+ }
656
+ };
598
657
  var WebSocketHandler = class {
599
658
  constructor(microservice, options) {
600
659
  this.microservice = microservice;
@@ -782,6 +841,7 @@ var Microservice = class {
782
841
  statisticsTimer;
783
842
  wsHandler;
784
843
  actionHandlers = /* @__PURE__ */ new Map();
844
+ pageHandlers = /* @__PURE__ */ new Map();
785
845
  activeRequests = /* @__PURE__ */ new Map();
786
846
  status = "running";
787
847
  modules = /* @__PURE__ */ new Map();
@@ -791,6 +851,7 @@ var Microservice = class {
791
851
  serviceId;
792
852
  constructor(options) {
793
853
  this.app = new hono.Hono();
854
+ this.app.use(timing.timing());
794
855
  this.nodeWebSocket = nodeWs.createNodeWebSocket({ app: this.app });
795
856
  this.serviceId = crypto.randomUUID();
796
857
  this.options = {
@@ -829,6 +890,11 @@ var Microservice = class {
829
890
  }
830
891
  await this.registerService(true);
831
892
  await this.initPlugins();
893
+ this.app.get(this.options.prefix, (ctx) => {
894
+ const name = this.options.name ?? "Microservice";
895
+ const version = this.options.version ?? "1.0.0";
896
+ return ctx.text(`${name} is ${this.status}. version: ${version}`);
897
+ });
832
898
  }
833
899
  async initModules() {
834
900
  for (const ModuleClass of this.options.modules) {
@@ -843,6 +909,7 @@ var Microservice = class {
843
909
  logger_default.info(`[ \u6CE8\u518C\u6A21\u5757 ] ${moduleName} ${metadata.options.description}`);
844
910
  this.modules.set(moduleName, moduleInstance);
845
911
  const actions = getActionMetadata(ModuleClass.prototype);
912
+ const pages = getPageMetadata(ModuleClass.prototype);
846
913
  for (const [actionName, actionMetadata] of Object.entries(actions)) {
847
914
  const handler = new ActionHandler(
848
915
  moduleInstance,
@@ -856,6 +923,18 @@ var Microservice = class {
856
923
  `[ \u6CE8\u518C\u52A8\u4F5C ] ${moduleName}.${actionName} ${actionMetadata.description} ${actionMetadata.mcp ? "MCP:" + actionMetadata.mcp?.type : ""}`
857
924
  );
858
925
  }
926
+ for (const [_, page] of Object.entries(pages)) {
927
+ const handler = new PageHandler(
928
+ moduleInstance,
929
+ page,
930
+ moduleName
931
+ );
932
+ this.pageHandlers.set(`${moduleName}.${page.name}`, handler);
933
+ this.app[page.method](`${this.options.prefix}${page.path}`, (ctx) => handler.handle(ctx));
934
+ logger_default.info(
935
+ `[ \u6CE8\u518C\u9875\u9762 ] ${moduleName}.${page.name} ${page.method.toUpperCase()} ${page.path} ${page.description}`
936
+ );
937
+ }
859
938
  const schedules = getScheduleMetadata(ModuleClass.prototype);
860
939
  if (schedules && Object.keys(schedules).length > 0) {
861
940
  if (!this.scheduler && this.etcdClient) {
@@ -885,11 +964,6 @@ var Microservice = class {
885
964
  initRoutes() {
886
965
  const startTime = Date.now();
887
966
  const prefix = this.options.prefix || "/api";
888
- this.app.get(prefix, (ctx) => {
889
- const name = this.options.name ?? "Microservice";
890
- const version = this.options.version ?? "1.0.0";
891
- return ctx.text(`${name} is ${this.status}. version: ${version}`);
892
- });
893
967
  this.app.get(`${prefix}/health`, (ctx) => {
894
968
  return ctx.json({
895
969
  status: "ok",
@@ -1332,28 +1406,6 @@ Received SIGTERM signal`);
1332
1406
  await this.waitingInitialization;
1333
1407
  }
1334
1408
  };
1335
-
1336
- // utils/checker.ts
1337
- async function startCheck(checkers, pass) {
1338
- logger_default.info("[ \u9884\u68C0\u5F00\u59CB ]");
1339
- for (const [index, checker] of checkers.entries()) {
1340
- const seq = index + 1;
1341
- logger_default.info(`${seq}. ${checker.name}`);
1342
- try {
1343
- if (checker.skip) {
1344
- logger_default.warn(`${seq}. ${checker.name} [\u8DF3\u8FC7]`);
1345
- continue;
1346
- }
1347
- await checker.check();
1348
- logger_default.info(`${seq}. ${checker.name} [\u6210\u529F]`);
1349
- } catch (error) {
1350
- logger_default.error(`${seq}. ${checker.name} [\u5931\u8D25]`);
1351
- throw error;
1352
- }
1353
- }
1354
- logger_default.info("[ \u9884\u68C0\u5B8C\u6210 ]");
1355
- if (pass) await pass();
1356
- }
1357
1409
  var HonoTransport = class {
1358
1410
  constructor(url, stream, closeStream) {
1359
1411
  this.url = url;
@@ -1469,22 +1521,227 @@ var ModelContextProtocolPlugin = class extends Plugin {
1469
1521
  );
1470
1522
  };
1471
1523
  };
1524
+ var DEFAULT_FAVICON = /* @__PURE__ */ jsxRuntime.jsx(
1525
+ "link",
1526
+ {
1527
+ rel: "icon",
1528
+ href: "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' width='100' height='100'><defs><linearGradient id='nodeGradient' x1='0%' y1='0%' x2='100%' y2='100%'><stop offset='0%' stop-color='%233498db'/><stop offset='100%' stop-color='%232980b9'/></linearGradient><linearGradient id='centerNodeGradient' x1='0%' y1='0%' x2='100%' y2='100%'><stop offset='0%' stop-color='%232ecc71'/><stop offset='100%' stop-color='%2327ae60'/></linearGradient></defs><circle cx='50' cy='50' r='45' fill='%23f5f7fa'/><path d='M30,30 L50,50' stroke='%23bdc3c7' stroke-width='2' stroke-linecap='round'/><path d='M70,30 L50,50' stroke='%23bdc3c7' stroke-width='2' stroke-linecap='round'/><path d='M30,70 L50,50' stroke='%23bdc3c7' stroke-width='2' stroke-linecap='round'/><path d='M70,70 L50,50' stroke='%23bdc3c7' stroke-width='2' stroke-linecap='round'/><polygon points='30,15 45,25 45,45 30,55 15,45 15,25' fill='url(%23nodeGradient)' stroke='%232980b9' stroke-width='1.5'/><polygon points='70,15 85,25 85,45 70,55 55,45 55,25' fill='url(%23nodeGradient)' stroke='%232980b9' stroke-width='1.5'/><polygon points='30,45 45,55 45,75 30,85 15,75 15,55' fill='url(%23nodeGradient)' stroke='%232980b9' stroke-width='1.5'/><polygon points='70,45 85,55 85,75 70,85 55,75 55,55' fill='url(%23nodeGradient)' stroke='%232980b9' stroke-width='1.5'/><polygon points='50,30 65,40 65,60 50,70 35,60 35,40' fill='url(%23centerNodeGradient)' stroke='%2327ae60' stroke-width='2'/><circle cx='30' cy='30' r='3' fill='%23ffffff'/><circle cx='70' cy='30' r='3' fill='%23ffffff'/><circle cx='30' cy='70' r='3' fill='%23ffffff'/><circle cx='70' cy='70' r='3' fill='%23ffffff'/><circle cx='50' cy='50' r='4' fill='%23ffffff'/></svg>",
1529
+ type: "image/svg+xml"
1530
+ }
1531
+ );
1532
+ var BaseLayout = (props = {
1533
+ title: "Microservice Template"
1534
+ }) => html.html`<!DOCTYPE html>
1535
+ <html>
1536
+ <head>
1537
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
1538
+ <title>${props.title}</title>
1539
+ ${props.heads}
1540
+ </head>
1541
+ <body>
1542
+ ${props.children}
1543
+ </body>
1544
+ </html>`;
1545
+ var HtmxLayout = (props = {
1546
+ title: "Microservice Template"
1547
+ }) => BaseLayout({
1548
+ title: props.title,
1549
+ heads: html.html`
1550
+ <script src="https://unpkg.com/htmx.org@latest"></script>
1551
+ <script src="https://unpkg.com/hyperscript.org@latest"></script>
1552
+ <script src="https://cdn.tailwindcss.com"></script>
1553
+ ${props.favicon || DEFAULT_FAVICON}
1554
+ `,
1555
+ children: props.children
1556
+ });
1557
+ var InfoCard = ({
1558
+ icon,
1559
+ iconColor,
1560
+ bgColor,
1561
+ label,
1562
+ value
1563
+ }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${bgColor} p-4 rounded-lg`, children: [
1564
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center mb-2", children: [
1565
+ /* @__PURE__ */ jsxRuntime.jsx(
1566
+ "svg",
1567
+ {
1568
+ className: `w-5 h-5 ${iconColor} mr-2`,
1569
+ fill: "none",
1570
+ stroke: "currentColor",
1571
+ viewBox: "0 0 24 24",
1572
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1573
+ "path",
1574
+ {
1575
+ strokeLinecap: "round",
1576
+ strokeLinejoin: "round",
1577
+ strokeWidth: 2,
1578
+ d: icon
1579
+ }
1580
+ )
1581
+ }
1582
+ ),
1583
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium text-gray-600", children: label })
1584
+ ] }),
1585
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: `text-xl font-semibold text-gray-900`, children: value })
1586
+ ] });
1587
+ var getEnvironmentBadgeClass = (env) => {
1588
+ switch (env) {
1589
+ case "prod":
1590
+ return "bg-red-100 text-red-800";
1591
+ case "stg":
1592
+ return "bg-yellow-100 text-yellow-800";
1593
+ case "dev":
1594
+ default:
1595
+ return "bg-blue-100 text-blue-800";
1596
+ }
1597
+ };
1598
+ var ServiceInfoCards = ({
1599
+ serviceInfo
1600
+ }) => {
1601
+ const infoCards = [
1602
+ {
1603
+ icon: "M7 4V2a1 1 0 011-1h8a1 1 0 011 1v2m-9 0h10m-10 0a2 2 0 00-2 2v14a2 2 0 002 2h10a2 2 0 002-2V6a2 2 0 00-2-2",
1604
+ iconColor: "text-blue-600",
1605
+ bgColor: "bg-blue-50",
1606
+ label: "\u670D\u52A1\u540D\u79F0",
1607
+ value: serviceInfo.name
1608
+ },
1609
+ {
1610
+ icon: "M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1",
1611
+ iconColor: "text-orange-600",
1612
+ bgColor: "bg-orange-50",
1613
+ label: "\u670D\u52A1\u8DEF\u5F84",
1614
+ value: serviceInfo.prefix || "/",
1615
+ isMonospace: true
1616
+ },
1617
+ {
1618
+ icon: "M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z",
1619
+ iconColor: "text-green-600",
1620
+ bgColor: "bg-green-50",
1621
+ label: "\u8FD0\u884C\u73AF\u5883",
1622
+ value: /* @__PURE__ */ jsxRuntime.jsx(
1623
+ "span",
1624
+ {
1625
+ className: `px-2 py-1 rounded-full text-sm ${getEnvironmentBadgeClass(serviceInfo.env ?? "dev")}`,
1626
+ children: serviceInfo.env ?? "dev"
1627
+ }
1628
+ )
1629
+ },
1630
+ {
1631
+ icon: "M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z",
1632
+ iconColor: "text-purple-600",
1633
+ bgColor: "bg-purple-50",
1634
+ label: "\u7248\u672C\u53F7",
1635
+ value: serviceInfo.version || "unknown"
1636
+ }
1637
+ ];
1638
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-white rounded-lg shadow-md p-6 mb-8", children: [
1639
+ /* @__PURE__ */ jsxRuntime.jsxs("h2", { className: "text-2xl font-semibold text-gray-800 mb-6 flex items-center", children: [
1640
+ /* @__PURE__ */ jsxRuntime.jsx(
1641
+ "svg",
1642
+ {
1643
+ className: "w-6 h-6 mr-2 text-blue-600",
1644
+ fill: "none",
1645
+ stroke: "currentColor",
1646
+ viewBox: "0 0 24 24",
1647
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1648
+ "path",
1649
+ {
1650
+ strokeLinecap: "round",
1651
+ strokeLinejoin: "round",
1652
+ strokeWidth: 2,
1653
+ d: "M13 10V3L4 14h7v7l9-11h-7z"
1654
+ }
1655
+ )
1656
+ }
1657
+ ),
1658
+ "\u670D\u52A1\u57FA\u672C\u4FE1\u606F"
1659
+ ] }),
1660
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-6", children: infoCards.map((card, index) => /* @__PURE__ */ jsxRuntime.jsx(InfoCard, { ...card }, index)) })
1661
+ ] });
1662
+ };
1663
+ var ServiceStatusPage = ({
1664
+ serviceInfo
1665
+ }) => {
1666
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-screen bg-gray-50 py-8", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-w-6xl mx-auto px-4", children: [
1667
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mb-8", children: /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-4xl font-bold text-gray-900 mb-2", children: "Service Status" }) }),
1668
+ /* @__PURE__ */ jsxRuntime.jsx(ServiceInfoCards, { serviceInfo })
1669
+ ] }) });
1670
+ };
1671
+ var ServiceStatusPage_default = ServiceStatusPage;
1672
+
1673
+ // core/plugins/page/mod.ts
1674
+ var PageRenderPlugin = class extends Plugin {
1675
+ constructor(options = {}) {
1676
+ super();
1677
+ this.options = options;
1678
+ }
1679
+ initialize = async (engine) => {
1680
+ const app = engine.getApp();
1681
+ if (this.options.useDefaultStatusPage) {
1682
+ app.get(`${engine.options.prefix}`, async (ctx) => {
1683
+ return ctx.html(HtmxLayout({
1684
+ title: engine.options.name,
1685
+ children: ServiceStatusPage_default({
1686
+ serviceInfo: {
1687
+ name: engine.options.name,
1688
+ prefix: engine.options.prefix,
1689
+ version: engine.options.version,
1690
+ env: engine.options.env,
1691
+ id: engine.serviceId,
1692
+ modules: engine.getModules(false)
1693
+ }
1694
+ })
1695
+ }));
1696
+ });
1697
+ }
1698
+ logger_default.info(`PageRenderPlugin enabled`);
1699
+ };
1700
+ };
1701
+
1702
+ // utils/checker.ts
1703
+ async function startCheck(checkers, pass) {
1704
+ logger_default.info("[ \u9884\u68C0\u5F00\u59CB ]");
1705
+ for (const [index, checker] of checkers.entries()) {
1706
+ const seq = index + 1;
1707
+ logger_default.info(`${seq}. ${checker.name}`);
1708
+ try {
1709
+ if (checker.skip) {
1710
+ logger_default.warn(`${seq}. ${checker.name} [\u8DF3\u8FC7]`);
1711
+ continue;
1712
+ }
1713
+ await checker.check();
1714
+ logger_default.info(`${seq}. ${checker.name} [\u6210\u529F]`);
1715
+ } catch (error) {
1716
+ logger_default.error(`${seq}. ${checker.name} [\u5931\u8D25]`);
1717
+ throw error;
1718
+ }
1719
+ }
1720
+ logger_default.info("[ \u9884\u68C0\u5B8C\u6210 ]");
1721
+ if (pass) await pass();
1722
+ }
1472
1723
 
1473
1724
  Object.defineProperty(exports, "dayjs", {
1474
1725
  enumerable: true,
1475
1726
  get: function () { return dayjs__default.default; }
1476
1727
  });
1477
1728
  exports.Action = Action;
1729
+ exports.BaseLayout = BaseLayout;
1478
1730
  exports.CacheAdapter = CacheAdapter;
1731
+ exports.HtmxLayout = HtmxLayout;
1479
1732
  exports.MemoryCacheAdapter = MemoryCacheAdapter;
1480
1733
  exports.Microservice = Microservice;
1481
1734
  exports.ModelContextProtocolPlugin = ModelContextProtocolPlugin;
1482
1735
  exports.Module = Module;
1736
+ exports.Page = Page;
1737
+ exports.PageRenderPlugin = PageRenderPlugin;
1483
1738
  exports.Plugin = Plugin;
1484
1739
  exports.RedisCacheAdapter = RedisCacheAdapter;
1485
1740
  exports.Schedule = Schedule;
1486
1741
  exports.ScheduleMode = ScheduleMode;
1487
1742
  exports.ServiceContext = ServiceContext;
1743
+ exports.ServiceInfoCards = ServiceInfoCards;
1744
+ exports.ServiceStatusPage = ServiceStatusPage;
1488
1745
  exports.logger = logger_default;
1489
1746
  exports.startCheck = startCheck;
1490
1747
  Object.keys(zod).forEach(function (k) {
package/dist/mod.d.cts CHANGED
@@ -6,6 +6,8 @@ import { Lease, Etcd3 } from 'etcd3';
6
6
  import { Hono } from 'hono';
7
7
  export { default as dayjs } from 'dayjs';
8
8
  import winston from 'winston';
9
+ import * as hono_utils_html from 'hono/utils/html';
10
+ import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
9
11
 
10
12
  declare abstract class CacheAdapter {
11
13
  abstract get(key: string): Promise<any>;
@@ -39,6 +41,14 @@ interface ActionOptions {
39
41
  stream?: boolean;
40
42
  mcp?: McpOptions;
41
43
  }
44
+ interface PageOptions {
45
+ method: "get" | "post" | "put" | "delete" | "patch" | "options";
46
+ path: string;
47
+ description?: string;
48
+ }
49
+ interface PageMetadata extends PageOptions {
50
+ name: string;
51
+ }
42
52
  interface ActionMetadata extends ActionOptions {
43
53
  name: string;
44
54
  idempotence: boolean;
@@ -226,6 +236,7 @@ declare class Microservice {
226
236
  private statisticsTimer?;
227
237
  private wsHandler?;
228
238
  private actionHandlers;
239
+ private pageHandlers;
229
240
  private activeRequests;
230
241
  private status;
231
242
  modules: Map<string, ModuleInfo>;
@@ -304,13 +315,6 @@ declare class Microservice {
304
315
  init(): Promise<void>;
305
316
  }
306
317
 
307
- interface PreStartChecker {
308
- name: string;
309
- check: () => Promise<void> | void;
310
- skip?: boolean;
311
- }
312
- declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
313
-
314
318
  declare class ModelContextProtocolPlugin extends Plugin {
315
319
  private mcpServer;
316
320
  private transports;
@@ -318,6 +322,40 @@ declare class ModelContextProtocolPlugin extends Plugin {
318
322
  initialize: (engine: Microservice) => Promise<void>;
319
323
  }
320
324
 
325
+ declare const BaseLayout: (props?: {
326
+ children?: any;
327
+ title?: string;
328
+ heads?: any;
329
+ }) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
330
+ declare const HtmxLayout: (props?: {
331
+ children?: any;
332
+ title: string;
333
+ favicon?: any;
334
+ }) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
335
+
336
+ declare const ServiceInfoCards: ({ serviceInfo, }: {
337
+ serviceInfo: ServiceInfo;
338
+ }) => hono_jsx_jsx_dev_runtime.JSX.Element;
339
+ declare const ServiceStatusPage: ({ serviceInfo, }: {
340
+ serviceInfo: ServiceInfo;
341
+ }) => hono_jsx_jsx_dev_runtime.JSX.Element;
342
+
343
+ interface PageRenderPluginOptions {
344
+ useDefaultStatusPage?: boolean;
345
+ }
346
+ declare class PageRenderPlugin extends Plugin {
347
+ private readonly options;
348
+ constructor(options?: PageRenderPluginOptions);
349
+ initialize: (engine: Microservice) => Promise<void>;
350
+ }
351
+
352
+ interface PreStartChecker {
353
+ name: string;
354
+ check: () => Promise<void> | void;
355
+ skip?: boolean;
356
+ }
357
+ declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
358
+
321
359
  /**
322
360
  * 用于给微服务模块方法添加的注解
323
361
  */
@@ -330,6 +368,11 @@ declare function Action(options: ActionOptions): Function;
330
368
  */
331
369
  declare function Module(name: string, options?: ModuleOptions): Function;
332
370
 
371
+ /**
372
+ * 用于给微服务模块方法添加的页面注解
373
+ */
374
+ declare function Page(options: PageOptions): Function;
375
+
333
376
  /**
334
377
  * 用于给微服务模块方法添加的调度注解
335
378
  */
@@ -337,4 +380,4 @@ declare function Schedule(options: ScheduleOptions): Function;
337
380
 
338
381
  declare const logger: winston.Logger;
339
382
 
340
- export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, CacheAdapter, type CacheFn, type CleanupHook, type EtcdConfig, type EventServiceInfo, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Plugin, type PreStartChecker, RedisCacheAdapter, type RequestInfo, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
383
+ export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, BaseLayout, CacheAdapter, type CacheFn, type CleanupHook, type EtcdConfig, type EventServiceInfo, HtmxLayout, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Page, type PageMetadata, type PageOptions, PageRenderPlugin, type PageRenderPluginOptions, Plugin, type PreStartChecker, RedisCacheAdapter, type RequestInfo, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, ServiceInfoCards, type ServiceStats, ServiceStatusPage, type StatisticsEvent, type StreamResponse, logger, startCheck };
package/dist/mod.d.ts CHANGED
@@ -6,6 +6,8 @@ import { Lease, Etcd3 } from 'etcd3';
6
6
  import { Hono } from 'hono';
7
7
  export { default as dayjs } from 'dayjs';
8
8
  import winston from 'winston';
9
+ import * as hono_utils_html from 'hono/utils/html';
10
+ import * as hono_jsx_jsx_dev_runtime from 'hono/jsx/jsx-dev-runtime';
9
11
 
10
12
  declare abstract class CacheAdapter {
11
13
  abstract get(key: string): Promise<any>;
@@ -39,6 +41,14 @@ interface ActionOptions {
39
41
  stream?: boolean;
40
42
  mcp?: McpOptions;
41
43
  }
44
+ interface PageOptions {
45
+ method: "get" | "post" | "put" | "delete" | "patch" | "options";
46
+ path: string;
47
+ description?: string;
48
+ }
49
+ interface PageMetadata extends PageOptions {
50
+ name: string;
51
+ }
42
52
  interface ActionMetadata extends ActionOptions {
43
53
  name: string;
44
54
  idempotence: boolean;
@@ -226,6 +236,7 @@ declare class Microservice {
226
236
  private statisticsTimer?;
227
237
  private wsHandler?;
228
238
  private actionHandlers;
239
+ private pageHandlers;
229
240
  private activeRequests;
230
241
  private status;
231
242
  modules: Map<string, ModuleInfo>;
@@ -304,13 +315,6 @@ declare class Microservice {
304
315
  init(): Promise<void>;
305
316
  }
306
317
 
307
- interface PreStartChecker {
308
- name: string;
309
- check: () => Promise<void> | void;
310
- skip?: boolean;
311
- }
312
- declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
313
-
314
318
  declare class ModelContextProtocolPlugin extends Plugin {
315
319
  private mcpServer;
316
320
  private transports;
@@ -318,6 +322,40 @@ declare class ModelContextProtocolPlugin extends Plugin {
318
322
  initialize: (engine: Microservice) => Promise<void>;
319
323
  }
320
324
 
325
+ declare const BaseLayout: (props?: {
326
+ children?: any;
327
+ title?: string;
328
+ heads?: any;
329
+ }) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
330
+ declare const HtmxLayout: (props?: {
331
+ children?: any;
332
+ title: string;
333
+ favicon?: any;
334
+ }) => hono_utils_html.HtmlEscapedString | Promise<hono_utils_html.HtmlEscapedString>;
335
+
336
+ declare const ServiceInfoCards: ({ serviceInfo, }: {
337
+ serviceInfo: ServiceInfo;
338
+ }) => hono_jsx_jsx_dev_runtime.JSX.Element;
339
+ declare const ServiceStatusPage: ({ serviceInfo, }: {
340
+ serviceInfo: ServiceInfo;
341
+ }) => hono_jsx_jsx_dev_runtime.JSX.Element;
342
+
343
+ interface PageRenderPluginOptions {
344
+ useDefaultStatusPage?: boolean;
345
+ }
346
+ declare class PageRenderPlugin extends Plugin {
347
+ private readonly options;
348
+ constructor(options?: PageRenderPluginOptions);
349
+ initialize: (engine: Microservice) => Promise<void>;
350
+ }
351
+
352
+ interface PreStartChecker {
353
+ name: string;
354
+ check: () => Promise<void> | void;
355
+ skip?: boolean;
356
+ }
357
+ declare function startCheck(checkers: PreStartChecker[], pass?: () => void | Promise<void>): Promise<void>;
358
+
321
359
  /**
322
360
  * 用于给微服务模块方法添加的注解
323
361
  */
@@ -330,6 +368,11 @@ declare function Action(options: ActionOptions): Function;
330
368
  */
331
369
  declare function Module(name: string, options?: ModuleOptions): Function;
332
370
 
371
+ /**
372
+ * 用于给微服务模块方法添加的页面注解
373
+ */
374
+ declare function Page(options: PageOptions): Function;
375
+
333
376
  /**
334
377
  * 用于给微服务模块方法添加的调度注解
335
378
  */
@@ -337,4 +380,4 @@ declare function Schedule(options: ScheduleOptions): Function;
337
380
 
338
381
  declare const logger: winston.Logger;
339
382
 
340
- export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, CacheAdapter, type CacheFn, type CleanupHook, type EtcdConfig, type EventServiceInfo, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Plugin, type PreStartChecker, RedisCacheAdapter, type RequestInfo, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, type ServiceStats, type StatisticsEvent, type StreamResponse, logger, startCheck };
383
+ export { Action, type ActionErrorEvent, type ActionMetadata, type ActionOptions, BaseLayout, CacheAdapter, type CacheFn, type CleanupHook, type EtcdConfig, type EventServiceInfo, HtmxLayout, type McpOptions, MemoryCacheAdapter, Microservice, type MicroserviceOptions, ModelContextProtocolPlugin, Module, type ModuleInfo, type ModuleMetadata, type ModuleOptions, Page, type PageMetadata, type PageOptions, PageRenderPlugin, type PageRenderPluginOptions, Plugin, type PreStartChecker, RedisCacheAdapter, type RequestInfo, Schedule, type ScheduleMetadata, ScheduleMode, type ScheduleOptions, ServiceContext, type ServiceInfo, ServiceInfoCards, type ServiceStats, ServiceStatusPage, type StatisticsEvent, type StreamResponse, logger, startCheck };