@zqagent/shared 0.0.0-stage → 0.1.0

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 (73) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +21 -2
  3. package/dist/approval-view.cjs +99 -0
  4. package/dist/approval-view.cjs.map +1 -0
  5. package/dist/approval-view.d.cts +39 -0
  6. package/dist/approval-view.d.ts +39 -0
  7. package/dist/approval-view.js +69 -0
  8. package/dist/approval-view.js.map +1 -0
  9. package/dist/fleet.cjs +263 -0
  10. package/dist/fleet.cjs.map +1 -0
  11. package/dist/fleet.d.cts +284 -0
  12. package/dist/fleet.d.ts +284 -0
  13. package/dist/fleet.js +214 -0
  14. package/dist/fleet.js.map +1 -0
  15. package/dist/hub-api.cjs +901 -0
  16. package/dist/hub-api.cjs.map +1 -0
  17. package/dist/hub-api.d.cts +1677 -0
  18. package/dist/hub-api.d.ts +1677 -0
  19. package/dist/hub-api.js +776 -0
  20. package/dist/hub-api.js.map +1 -0
  21. package/dist/index-DokiNlGJ.d.cts +182 -0
  22. package/dist/index-DokiNlGJ.d.ts +182 -0
  23. package/dist/index.cjs +861 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +7 -0
  26. package/dist/index.d.ts +7 -0
  27. package/dist/index.js +779 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/llm-presets.cjs +92 -0
  30. package/dist/llm-presets.cjs.map +1 -0
  31. package/dist/llm-presets.d.cts +28 -0
  32. package/dist/llm-presets.d.ts +28 -0
  33. package/dist/llm-presets.js +66 -0
  34. package/dist/llm-presets.js.map +1 -0
  35. package/dist/media.cjs +111 -0
  36. package/dist/media.cjs.map +1 -0
  37. package/dist/media.d.cts +59 -0
  38. package/dist/media.d.ts +59 -0
  39. package/dist/media.js +79 -0
  40. package/dist/media.js.map +1 -0
  41. package/dist/messages-CiXjdR1Z.d.cts +257 -0
  42. package/dist/messages-CiXjdR1Z.d.ts +257 -0
  43. package/dist/model-capabilities.cjs +105 -0
  44. package/dist/model-capabilities.cjs.map +1 -0
  45. package/dist/model-capabilities.d.cts +46 -0
  46. package/dist/model-capabilities.d.ts +46 -0
  47. package/dist/model-capabilities.js +74 -0
  48. package/dist/model-capabilities.js.map +1 -0
  49. package/dist/notify/index.cjs +375 -0
  50. package/dist/notify/index.cjs.map +1 -0
  51. package/dist/notify/index.d.cts +2 -0
  52. package/dist/notify/index.d.ts +2 -0
  53. package/dist/notify/index.js +330 -0
  54. package/dist/notify/index.js.map +1 -0
  55. package/dist/secrets.cjs +121 -0
  56. package/dist/secrets.cjs.map +1 -0
  57. package/dist/secrets.d.cts +25 -0
  58. package/dist/secrets.d.ts +25 -0
  59. package/dist/secrets.js +82 -0
  60. package/dist/secrets.js.map +1 -0
  61. package/dist/wire/index.cjs +1163 -0
  62. package/dist/wire/index.cjs.map +1 -0
  63. package/dist/wire/index.d.cts +166 -0
  64. package/dist/wire/index.d.ts +166 -0
  65. package/dist/wire/index.js +1081 -0
  66. package/dist/wire/index.js.map +1 -0
  67. package/dist/wire/node.cjs +224 -0
  68. package/dist/wire/node.cjs.map +1 -0
  69. package/dist/wire/node.d.cts +14 -0
  70. package/dist/wire/node.d.ts +14 -0
  71. package/dist/wire/node.js +195 -0
  72. package/dist/wire/node.js.map +1 -0
  73. package/package.json +99 -3
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Chengdu Zhiqian Technology Co., Ltd.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # @zqagent/shared
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ core 与 hub 共用的基础模块(不依赖任何业务包)。core/hub 通过各自 `tsconfig` 的 `paths`
4
+ 直接引用本包源码,构建期打进各自 bundle。
5
+
6
+ | 子路径 | 内容 |
7
+ | --- | --- |
8
+ | `@zqagent/shared/fleet` | MQTT 节点管理协议 v2(topic / 签名 / nonce / 时间戳) |
9
+ | `@zqagent/shared/secrets` | 凭据加密 `SecretBox`(AES-256-GCM) |
10
+ | `@zqagent/shared/approval-view` | 审批视图(表格 HTML/Markdown) |
11
+ | `@zqagent/shared/notify` | 通知抽象与渠道(Bark / Server酱 / Webhook / Email) |
12
+ | 根 | 以上全部 |
13
+
14
+ ## 命令
15
+
16
+ ```bash
17
+ pnpm --filter @zqagent/shared typecheck
18
+ pnpm --filter @zqagent/shared build # tsup → dist/(ESM+CJS+dts)
19
+ pnpm --filter @zqagent/shared dev # watch
20
+ ```
21
+
22
+ 详见 [../../docs/shared.md](../../docs/shared.md)。
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/approval-view.ts
21
+ var approval_view_exports = {};
22
+ __export(approval_view_exports, {
23
+ APPROVAL_COLUMNS: () => APPROVAL_COLUMNS,
24
+ APPROVAL_VALUE_MAX: () => APPROVAL_VALUE_MAX,
25
+ approvalFields: () => approvalFields,
26
+ approvalInputFromData: () => approvalInputFromData,
27
+ approvalToHtmlTable: () => approvalToHtmlTable,
28
+ approvalToMarkdownTable: () => approvalToMarkdownTable
29
+ });
30
+ module.exports = __toCommonJS(approval_view_exports);
31
+ var APPROVAL_VALUE_MAX = 120;
32
+ var APPROVAL_COLUMNS = ["\u9879\u76EE", "\u8BE6\u60C5"];
33
+ var TOOL_LABEL = "\u{1F527} \u5DE5\u5177";
34
+ var REASON_LABEL = "\u{1F4AC} \u539F\u56E0";
35
+ function formatValue(v, maxLen) {
36
+ let text;
37
+ if (v == null) {
38
+ text = "";
39
+ } else if (typeof v === "string") {
40
+ text = v;
41
+ } else {
42
+ try {
43
+ text = JSON.stringify(v);
44
+ } catch {
45
+ text = String(v);
46
+ }
47
+ }
48
+ text = text.replace(/\r?\n/g, "\u21B5");
49
+ return text.length > maxLen ? text.slice(0, maxLen) + "\u2026" : text;
50
+ }
51
+ function approvalInputFromData(data) {
52
+ const args = data["arguments"];
53
+ return {
54
+ toolName: String(data["toolName"] ?? ""),
55
+ reason: String(data["reason"] ?? ""),
56
+ arguments: args && typeof args === "object" ? args : void 0
57
+ };
58
+ }
59
+ function approvalFields(input, maxLen = APPROVAL_VALUE_MAX) {
60
+ const fields = [
61
+ { label: TOOL_LABEL, value: formatValue(input.toolName, maxLen) },
62
+ { label: REASON_LABEL, value: formatValue(input.reason, maxLen) }
63
+ ];
64
+ for (const [key, value] of Object.entries(input.arguments ?? {})) {
65
+ fields.push({ label: formatValue(key, maxLen), value: formatValue(value, maxLen) });
66
+ }
67
+ return fields;
68
+ }
69
+ function escapeCell(text) {
70
+ return text.replace(/\|/g, "\\|").replace(/\r?\n/g, "\u21B5");
71
+ }
72
+ function approvalToMarkdownTable(input, opts = {}) {
73
+ const lines = [];
74
+ if (opts.title) lines.push(opts.title, "");
75
+ lines.push(`| ${APPROVAL_COLUMNS[0]} | ${APPROVAL_COLUMNS[1]} |`, "| --- | --- |");
76
+ for (const f of approvalFields(input, opts.maxLen)) {
77
+ lines.push(`| ${escapeCell(f.label)} | ${escapeCell(f.value)} |`);
78
+ }
79
+ return lines.join("\n");
80
+ }
81
+ function escapeHtml(text) {
82
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
83
+ }
84
+ function approvalToHtmlTable(input, maxLen = APPROVAL_VALUE_MAX) {
85
+ const rows = approvalFields(input, maxLen).map(
86
+ (f) => `<tr><th style="text-align:left;padding:4px 12px 4px 0;color:#6b7280;font-weight:500;white-space:nowrap;vertical-align:top;">${escapeHtml(f.label)}</th><td style="padding:4px 0;font-family:ui-monospace,Menlo,Consolas,monospace;">${escapeHtml(f.value)}</td></tr>`
87
+ ).join("");
88
+ return `<table style="border-collapse:collapse;font-size:13px;">${rows}</table>`;
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ APPROVAL_COLUMNS,
93
+ APPROVAL_VALUE_MAX,
94
+ approvalFields,
95
+ approvalInputFromData,
96
+ approvalToHtmlTable,
97
+ approvalToMarkdownTable
98
+ });
99
+ //# sourceMappingURL=approval-view.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/approval-view.ts"],"sourcesContent":["/**\n * 审批视图:把审批请求(工具 / 原因 / 参数详情)规范化为统一的「字段行」,\n * 供 CLI、QQ、通用通知、邮件、MQTT、Web 等各端渲染成同一套表格。\n *\n * 唯一数据源是审批事件负载(toolName / reason / arguments),各通道只负责\n * 把这里产出的字段渲染成自己端上最好看的形态(终端框线表 / Markdown / HTML)。\n */\n\n/** 审批表格中的一行 */\nexport interface ApprovalField {\n /** 字段名(工具 / 原因 / 参数名) */\n label: string;\n /** 字段值(已完成换行折叠与截断) */\n value: string;\n}\n\n/** 统一审批输入 */\nexport interface ApprovalViewInput {\n toolName: string;\n reason: string;\n arguments?: Record<string, unknown> | null;\n}\n\n/** 单个字段值的默认最大长度(超出以 … 截断) */\nexport const APPROVAL_VALUE_MAX = 120;\n\n/** 表格列标题(各端保持一致) */\nexport const APPROVAL_COLUMNS = [\"项目\", \"详情\"] as const;\n\n/** 工具 / 原因两行的固定文案 */\nconst TOOL_LABEL = \"🔧 工具\";\nconst REASON_LABEL = \"💬 原因\";\n\n/** 把任意参数值折叠成单行文本并按需截断 */\nfunction formatValue(v: unknown, maxLen: number): string {\n let text: string;\n if (v == null) {\n text = \"\";\n } else if (typeof v === \"string\") {\n text = v;\n } else {\n try {\n text = JSON.stringify(v);\n } catch {\n text = String(v);\n }\n }\n text = text.replace(/\\r?\\n/g, \"↵\");\n return text.length > maxLen ? text.slice(0, maxLen) + \"…\" : text;\n}\n\n/** 从 NotifyEvent.data(审批事件负载)提取统一输入 */\nexport function approvalInputFromData(\n data: Record<string, unknown>,\n): ApprovalViewInput {\n const args = data[\"arguments\"];\n return {\n toolName: String(data[\"toolName\"] ?? \"\"),\n reason: String(data[\"reason\"] ?? \"\"),\n arguments:\n args && typeof args === \"object\"\n ? (args as Record<string, unknown>)\n : undefined,\n };\n}\n\n/**\n * 规范化为统一字段行:工具 → 原因 → 每个参数各一行(行序在所有通道一致)。\n */\nexport function approvalFields(\n input: ApprovalViewInput,\n maxLen = APPROVAL_VALUE_MAX,\n): ApprovalField[] {\n const fields: ApprovalField[] = [\n { label: TOOL_LABEL, value: formatValue(input.toolName, maxLen) },\n { label: REASON_LABEL, value: formatValue(input.reason, maxLen) },\n ];\n for (const [key, value] of Object.entries(input.arguments ?? {})) {\n fields.push({ label: formatValue(key, maxLen), value: formatValue(value, maxLen) });\n }\n return fields;\n}\n\n/** Markdown 表格单元格转义(竖线会破坏列结构) */\nfunction escapeCell(text: string): string {\n return text.replace(/\\|/g, \"\\\\|\").replace(/\\r?\\n/g, \"↵\");\n}\n\n/** 渲染为统一的两列 Markdown 表格 */\nexport function approvalToMarkdownTable(\n input: ApprovalViewInput,\n opts: { maxLen?: number; title?: string } = {},\n): string {\n const lines: string[] = [];\n if (opts.title) lines.push(opts.title, \"\");\n lines.push(`| ${APPROVAL_COLUMNS[0]} | ${APPROVAL_COLUMNS[1]} |`, \"| --- | --- |\");\n for (const f of approvalFields(input, opts.maxLen)) {\n lines.push(`| ${escapeCell(f.label)} | ${escapeCell(f.value)} |`);\n }\n return lines.join(\"\\n\");\n}\n\n/** HTML 转义 */\nfunction escapeHtml(text: string): string {\n return text\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\");\n}\n\n/** 渲染为 HTML 表格(邮件 / Web 端直接展示为真正的表格) */\nexport function approvalToHtmlTable(\n input: ApprovalViewInput,\n maxLen = APPROVAL_VALUE_MAX,\n): string {\n const rows = approvalFields(input, maxLen)\n .map(\n (f) =>\n `<tr>` +\n `<th style=\"text-align:left;padding:4px 12px 4px 0;color:#6b7280;font-weight:500;white-space:nowrap;vertical-align:top;\">${escapeHtml(f.label)}</th>` +\n `<td style=\"padding:4px 0;font-family:ui-monospace,Menlo,Consolas,monospace;\">${escapeHtml(f.value)}</td>` +\n `</tr>`,\n )\n .join(\"\");\n return `<table style=\"border-collapse:collapse;font-size:13px;\">${rows}</table>`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,IAAM,qBAAqB;AAG3B,IAAM,mBAAmB,CAAC,gBAAM,cAAI;AAG3C,IAAM,aAAa;AACnB,IAAM,eAAe;AAGrB,SAAS,YAAY,GAAY,QAAwB;AACvD,MAAI;AACJ,MAAI,KAAK,MAAM;AACb,WAAO;AAAA,EACT,WAAW,OAAO,MAAM,UAAU;AAChC,WAAO;AAAA,EACT,OAAO;AACL,QAAI;AACF,aAAO,KAAK,UAAU,CAAC;AAAA,IACzB,QAAQ;AACN,aAAO,OAAO,CAAC;AAAA,IACjB;AAAA,EACF;AACA,SAAO,KAAK,QAAQ,UAAU,QAAG;AACjC,SAAO,KAAK,SAAS,SAAS,KAAK,MAAM,GAAG,MAAM,IAAI,WAAM;AAC9D;AAGO,SAAS,sBACd,MACmB;AACnB,QAAM,OAAO,KAAK,WAAW;AAC7B,SAAO;AAAA,IACL,UAAU,OAAO,KAAK,UAAU,KAAK,EAAE;AAAA,IACvC,QAAQ,OAAO,KAAK,QAAQ,KAAK,EAAE;AAAA,IACnC,WACE,QAAQ,OAAO,SAAS,WACnB,OACD;AAAA,EACR;AACF;AAKO,SAAS,eACd,OACA,SAAS,oBACQ;AACjB,QAAM,SAA0B;AAAA,IAC9B,EAAE,OAAO,YAAY,OAAO,YAAY,MAAM,UAAU,MAAM,EAAE;AAAA,IAChE,EAAE,OAAO,cAAc,OAAO,YAAY,MAAM,QAAQ,MAAM,EAAE;AAAA,EAClE;AACA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,aAAa,CAAC,CAAC,GAAG;AAChE,WAAO,KAAK,EAAE,OAAO,YAAY,KAAK,MAAM,GAAG,OAAO,YAAY,OAAO,MAAM,EAAE,CAAC;AAAA,EACpF;AACA,SAAO;AACT;AAGA,SAAS,WAAW,MAAsB;AACxC,SAAO,KAAK,QAAQ,OAAO,KAAK,EAAE,QAAQ,UAAU,QAAG;AACzD;AAGO,SAAS,wBACd,OACA,OAA4C,CAAC,GACrC;AACR,QAAM,QAAkB,CAAC;AACzB,MAAI,KAAK,MAAO,OAAM,KAAK,KAAK,OAAO,EAAE;AACzC,QAAM,KAAK,KAAK,iBAAiB,CAAC,CAAC,MAAM,iBAAiB,CAAC,CAAC,MAAM,eAAe;AACjF,aAAW,KAAK,eAAe,OAAO,KAAK,MAAM,GAAG;AAClD,UAAM,KAAK,KAAK,WAAW,EAAE,KAAK,CAAC,MAAM,WAAW,EAAE,KAAK,CAAC,IAAI;AAAA,EAClE;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;AAGA,SAAS,WAAW,MAAsB;AACxC,SAAO,KACJ,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM;AACzB;AAGO,SAAS,oBACd,OACA,SAAS,oBACD;AACR,QAAM,OAAO,eAAe,OAAO,MAAM,EACtC;AAAA,IACC,CAAC,MACC,+HAC2H,WAAW,EAAE,KAAK,CAAC,qFAC9D,WAAW,EAAE,KAAK,CAAC;AAAA,EAEvG,EACC,KAAK,EAAE;AACV,SAAO,2DAA2D,IAAI;AACxE;","names":[]}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 审批视图:把审批请求(工具 / 原因 / 参数详情)规范化为统一的「字段行」,
3
+ * 供 CLI、QQ、通用通知、邮件、MQTT、Web 等各端渲染成同一套表格。
4
+ *
5
+ * 唯一数据源是审批事件负载(toolName / reason / arguments),各通道只负责
6
+ * 把这里产出的字段渲染成自己端上最好看的形态(终端框线表 / Markdown / HTML)。
7
+ */
8
+ /** 审批表格中的一行 */
9
+ interface ApprovalField {
10
+ /** 字段名(工具 / 原因 / 参数名) */
11
+ label: string;
12
+ /** 字段值(已完成换行折叠与截断) */
13
+ value: string;
14
+ }
15
+ /** 统一审批输入 */
16
+ interface ApprovalViewInput {
17
+ toolName: string;
18
+ reason: string;
19
+ arguments?: Record<string, unknown> | null;
20
+ }
21
+ /** 单个字段值的默认最大长度(超出以 … 截断) */
22
+ declare const APPROVAL_VALUE_MAX = 120;
23
+ /** 表格列标题(各端保持一致) */
24
+ declare const APPROVAL_COLUMNS: readonly ["项目", "详情"];
25
+ /** 从 NotifyEvent.data(审批事件负载)提取统一输入 */
26
+ declare function approvalInputFromData(data: Record<string, unknown>): ApprovalViewInput;
27
+ /**
28
+ * 规范化为统一字段行:工具 → 原因 → 每个参数各一行(行序在所有通道一致)。
29
+ */
30
+ declare function approvalFields(input: ApprovalViewInput, maxLen?: number): ApprovalField[];
31
+ /** 渲染为统一的两列 Markdown 表格 */
32
+ declare function approvalToMarkdownTable(input: ApprovalViewInput, opts?: {
33
+ maxLen?: number;
34
+ title?: string;
35
+ }): string;
36
+ /** 渲染为 HTML 表格(邮件 / Web 端直接展示为真正的表格) */
37
+ declare function approvalToHtmlTable(input: ApprovalViewInput, maxLen?: number): string;
38
+
39
+ export { APPROVAL_COLUMNS, APPROVAL_VALUE_MAX, type ApprovalField, type ApprovalViewInput, approvalFields, approvalInputFromData, approvalToHtmlTable, approvalToMarkdownTable };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * 审批视图:把审批请求(工具 / 原因 / 参数详情)规范化为统一的「字段行」,
3
+ * 供 CLI、QQ、通用通知、邮件、MQTT、Web 等各端渲染成同一套表格。
4
+ *
5
+ * 唯一数据源是审批事件负载(toolName / reason / arguments),各通道只负责
6
+ * 把这里产出的字段渲染成自己端上最好看的形态(终端框线表 / Markdown / HTML)。
7
+ */
8
+ /** 审批表格中的一行 */
9
+ interface ApprovalField {
10
+ /** 字段名(工具 / 原因 / 参数名) */
11
+ label: string;
12
+ /** 字段值(已完成换行折叠与截断) */
13
+ value: string;
14
+ }
15
+ /** 统一审批输入 */
16
+ interface ApprovalViewInput {
17
+ toolName: string;
18
+ reason: string;
19
+ arguments?: Record<string, unknown> | null;
20
+ }
21
+ /** 单个字段值的默认最大长度(超出以 … 截断) */
22
+ declare const APPROVAL_VALUE_MAX = 120;
23
+ /** 表格列标题(各端保持一致) */
24
+ declare const APPROVAL_COLUMNS: readonly ["项目", "详情"];
25
+ /** 从 NotifyEvent.data(审批事件负载)提取统一输入 */
26
+ declare function approvalInputFromData(data: Record<string, unknown>): ApprovalViewInput;
27
+ /**
28
+ * 规范化为统一字段行:工具 → 原因 → 每个参数各一行(行序在所有通道一致)。
29
+ */
30
+ declare function approvalFields(input: ApprovalViewInput, maxLen?: number): ApprovalField[];
31
+ /** 渲染为统一的两列 Markdown 表格 */
32
+ declare function approvalToMarkdownTable(input: ApprovalViewInput, opts?: {
33
+ maxLen?: number;
34
+ title?: string;
35
+ }): string;
36
+ /** 渲染为 HTML 表格(邮件 / Web 端直接展示为真正的表格) */
37
+ declare function approvalToHtmlTable(input: ApprovalViewInput, maxLen?: number): string;
38
+
39
+ export { APPROVAL_COLUMNS, APPROVAL_VALUE_MAX, type ApprovalField, type ApprovalViewInput, approvalFields, approvalInputFromData, approvalToHtmlTable, approvalToMarkdownTable };
@@ -0,0 +1,69 @@
1
+ // src/approval-view.ts
2
+ var APPROVAL_VALUE_MAX = 120;
3
+ var APPROVAL_COLUMNS = ["\u9879\u76EE", "\u8BE6\u60C5"];
4
+ var TOOL_LABEL = "\u{1F527} \u5DE5\u5177";
5
+ var REASON_LABEL = "\u{1F4AC} \u539F\u56E0";
6
+ function formatValue(v, maxLen) {
7
+ let text;
8
+ if (v == null) {
9
+ text = "";
10
+ } else if (typeof v === "string") {
11
+ text = v;
12
+ } else {
13
+ try {
14
+ text = JSON.stringify(v);
15
+ } catch {
16
+ text = String(v);
17
+ }
18
+ }
19
+ text = text.replace(/\r?\n/g, "\u21B5");
20
+ return text.length > maxLen ? text.slice(0, maxLen) + "\u2026" : text;
21
+ }
22
+ function approvalInputFromData(data) {
23
+ const args = data["arguments"];
24
+ return {
25
+ toolName: String(data["toolName"] ?? ""),
26
+ reason: String(data["reason"] ?? ""),
27
+ arguments: args && typeof args === "object" ? args : void 0
28
+ };
29
+ }
30
+ function approvalFields(input, maxLen = APPROVAL_VALUE_MAX) {
31
+ const fields = [
32
+ { label: TOOL_LABEL, value: formatValue(input.toolName, maxLen) },
33
+ { label: REASON_LABEL, value: formatValue(input.reason, maxLen) }
34
+ ];
35
+ for (const [key, value] of Object.entries(input.arguments ?? {})) {
36
+ fields.push({ label: formatValue(key, maxLen), value: formatValue(value, maxLen) });
37
+ }
38
+ return fields;
39
+ }
40
+ function escapeCell(text) {
41
+ return text.replace(/\|/g, "\\|").replace(/\r?\n/g, "\u21B5");
42
+ }
43
+ function approvalToMarkdownTable(input, opts = {}) {
44
+ const lines = [];
45
+ if (opts.title) lines.push(opts.title, "");
46
+ lines.push(`| ${APPROVAL_COLUMNS[0]} | ${APPROVAL_COLUMNS[1]} |`, "| --- | --- |");
47
+ for (const f of approvalFields(input, opts.maxLen)) {
48
+ lines.push(`| ${escapeCell(f.label)} | ${escapeCell(f.value)} |`);
49
+ }
50
+ return lines.join("\n");
51
+ }
52
+ function escapeHtml(text) {
53
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
54
+ }
55
+ function approvalToHtmlTable(input, maxLen = APPROVAL_VALUE_MAX) {
56
+ const rows = approvalFields(input, maxLen).map(
57
+ (f) => `<tr><th style="text-align:left;padding:4px 12px 4px 0;color:#6b7280;font-weight:500;white-space:nowrap;vertical-align:top;">${escapeHtml(f.label)}</th><td style="padding:4px 0;font-family:ui-monospace,Menlo,Consolas,monospace;">${escapeHtml(f.value)}</td></tr>`
58
+ ).join("");
59
+ return `<table style="border-collapse:collapse;font-size:13px;">${rows}</table>`;
60
+ }
61
+ export {
62
+ APPROVAL_COLUMNS,
63
+ APPROVAL_VALUE_MAX,
64
+ approvalFields,
65
+ approvalInputFromData,
66
+ approvalToHtmlTable,
67
+ approvalToMarkdownTable
68
+ };
69
+ //# sourceMappingURL=approval-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/approval-view.ts"],"sourcesContent":["/**\n * 审批视图:把审批请求(工具 / 原因 / 参数详情)规范化为统一的「字段行」,\n * 供 CLI、QQ、通用通知、邮件、MQTT、Web 等各端渲染成同一套表格。\n *\n * 唯一数据源是审批事件负载(toolName / reason / arguments),各通道只负责\n * 把这里产出的字段渲染成自己端上最好看的形态(终端框线表 / Markdown / HTML)。\n */\n\n/** 审批表格中的一行 */\nexport interface ApprovalField {\n /** 字段名(工具 / 原因 / 参数名) */\n label: string;\n /** 字段值(已完成换行折叠与截断) */\n value: string;\n}\n\n/** 统一审批输入 */\nexport interface ApprovalViewInput {\n toolName: string;\n reason: string;\n arguments?: Record<string, unknown> | null;\n}\n\n/** 单个字段值的默认最大长度(超出以 … 截断) */\nexport const APPROVAL_VALUE_MAX = 120;\n\n/** 表格列标题(各端保持一致) */\nexport const APPROVAL_COLUMNS = [\"项目\", \"详情\"] as const;\n\n/** 工具 / 原因两行的固定文案 */\nconst TOOL_LABEL = \"🔧 工具\";\nconst REASON_LABEL = \"💬 原因\";\n\n/** 把任意参数值折叠成单行文本并按需截断 */\nfunction formatValue(v: unknown, maxLen: number): string {\n let text: string;\n if (v == null) {\n text = \"\";\n } else if (typeof v === \"string\") {\n text = v;\n } else {\n try {\n text = JSON.stringify(v);\n } catch {\n text = String(v);\n }\n }\n text = text.replace(/\\r?\\n/g, \"↵\");\n return text.length > maxLen ? text.slice(0, maxLen) + \"…\" : text;\n}\n\n/** 从 NotifyEvent.data(审批事件负载)提取统一输入 */\nexport function approvalInputFromData(\n data: Record<string, unknown>,\n): ApprovalViewInput {\n const args = data[\"arguments\"];\n return {\n toolName: String(data[\"toolName\"] ?? \"\"),\n reason: String(data[\"reason\"] ?? \"\"),\n arguments:\n args && typeof args === \"object\"\n ? (args as Record<string, unknown>)\n : undefined,\n };\n}\n\n/**\n * 规范化为统一字段行:工具 → 原因 → 每个参数各一行(行序在所有通道一致)。\n */\nexport function approvalFields(\n input: ApprovalViewInput,\n maxLen = APPROVAL_VALUE_MAX,\n): ApprovalField[] {\n const fields: ApprovalField[] = [\n { label: TOOL_LABEL, value: formatValue(input.toolName, maxLen) },\n { label: REASON_LABEL, value: formatValue(input.reason, maxLen) },\n ];\n for (const [key, value] of Object.entries(input.arguments ?? {})) {\n fields.push({ label: formatValue(key, maxLen), value: formatValue(value, maxLen) });\n }\n return fields;\n}\n\n/** Markdown 表格单元格转义(竖线会破坏列结构) */\nfunction escapeCell(text: string): string {\n return text.replace(/\\|/g, \"\\\\|\").replace(/\\r?\\n/g, \"↵\");\n}\n\n/** 渲染为统一的两列 Markdown 表格 */\nexport function approvalToMarkdownTable(\n input: ApprovalViewInput,\n opts: { maxLen?: number; title?: string } = {},\n): string {\n const lines: string[] = [];\n if (opts.title) lines.push(opts.title, \"\");\n lines.push(`| ${APPROVAL_COLUMNS[0]} | ${APPROVAL_COLUMNS[1]} |`, \"| --- | --- |\");\n for (const f of approvalFields(input, opts.maxLen)) {\n lines.push(`| ${escapeCell(f.label)} | ${escapeCell(f.value)} |`);\n }\n return lines.join(\"\\n\");\n}\n\n/** HTML 转义 */\nfunction escapeHtml(text: string): string {\n return text\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\");\n}\n\n/** 渲染为 HTML 表格(邮件 / Web 端直接展示为真正的表格) */\nexport function approvalToHtmlTable(\n input: ApprovalViewInput,\n maxLen = APPROVAL_VALUE_MAX,\n): string {\n const rows = approvalFields(input, maxLen)\n .map(\n (f) =>\n `<tr>` +\n `<th style=\"text-align:left;padding:4px 12px 4px 0;color:#6b7280;font-weight:500;white-space:nowrap;vertical-align:top;\">${escapeHtml(f.label)}</th>` +\n `<td style=\"padding:4px 0;font-family:ui-monospace,Menlo,Consolas,monospace;\">${escapeHtml(f.value)}</td>` +\n `</tr>`,\n )\n .join(\"\");\n return `<table style=\"border-collapse:collapse;font-size:13px;\">${rows}</table>`;\n}\n"],"mappings":";AAwBO,IAAM,qBAAqB;AAG3B,IAAM,mBAAmB,CAAC,gBAAM,cAAI;AAG3C,IAAM,aAAa;AACnB,IAAM,eAAe;AAGrB,SAAS,YAAY,GAAY,QAAwB;AACvD,MAAI;AACJ,MAAI,KAAK,MAAM;AACb,WAAO;AAAA,EACT,WAAW,OAAO,MAAM,UAAU;AAChC,WAAO;AAAA,EACT,OAAO;AACL,QAAI;AACF,aAAO,KAAK,UAAU,CAAC;AAAA,IACzB,QAAQ;AACN,aAAO,OAAO,CAAC;AAAA,IACjB;AAAA,EACF;AACA,SAAO,KAAK,QAAQ,UAAU,QAAG;AACjC,SAAO,KAAK,SAAS,SAAS,KAAK,MAAM,GAAG,MAAM,IAAI,WAAM;AAC9D;AAGO,SAAS,sBACd,MACmB;AACnB,QAAM,OAAO,KAAK,WAAW;AAC7B,SAAO;AAAA,IACL,UAAU,OAAO,KAAK,UAAU,KAAK,EAAE;AAAA,IACvC,QAAQ,OAAO,KAAK,QAAQ,KAAK,EAAE;AAAA,IACnC,WACE,QAAQ,OAAO,SAAS,WACnB,OACD;AAAA,EACR;AACF;AAKO,SAAS,eACd,OACA,SAAS,oBACQ;AACjB,QAAM,SAA0B;AAAA,IAC9B,EAAE,OAAO,YAAY,OAAO,YAAY,MAAM,UAAU,MAAM,EAAE;AAAA,IAChE,EAAE,OAAO,cAAc,OAAO,YAAY,MAAM,QAAQ,MAAM,EAAE;AAAA,EAClE;AACA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,aAAa,CAAC,CAAC,GAAG;AAChE,WAAO,KAAK,EAAE,OAAO,YAAY,KAAK,MAAM,GAAG,OAAO,YAAY,OAAO,MAAM,EAAE,CAAC;AAAA,EACpF;AACA,SAAO;AACT;AAGA,SAAS,WAAW,MAAsB;AACxC,SAAO,KAAK,QAAQ,OAAO,KAAK,EAAE,QAAQ,UAAU,QAAG;AACzD;AAGO,SAAS,wBACd,OACA,OAA4C,CAAC,GACrC;AACR,QAAM,QAAkB,CAAC;AACzB,MAAI,KAAK,MAAO,OAAM,KAAK,KAAK,OAAO,EAAE;AACzC,QAAM,KAAK,KAAK,iBAAiB,CAAC,CAAC,MAAM,iBAAiB,CAAC,CAAC,MAAM,eAAe;AACjF,aAAW,KAAK,eAAe,OAAO,KAAK,MAAM,GAAG;AAClD,UAAM,KAAK,KAAK,WAAW,EAAE,KAAK,CAAC,MAAM,WAAW,EAAE,KAAK,CAAC,IAAI;AAAA,EAClE;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;AAGA,SAAS,WAAW,MAAsB;AACxC,SAAO,KACJ,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM;AACzB;AAGO,SAAS,oBACd,OACA,SAAS,oBACD;AACR,QAAM,OAAO,eAAe,OAAO,MAAM,EACtC;AAAA,IACC,CAAC,MACC,+HAC2H,WAAW,EAAE,KAAK,CAAC,qFAC9D,WAAW,EAAE,KAAK,CAAC;AAAA,EAEvG,EACC,KAAK,EAAE;AACV,SAAO,2DAA2D,IAAI;AACxE;","names":[]}