@webskill/sdk 0.21.0 → 0.22.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.
- package/dist/abnfDiagram-O67JEVCF-DtYFjfqO.js +109 -0
- package/dist/agent.d.ts +3 -3
- package/dist/agent.js +1012 -130
- package/dist/{approval-DwN2o2QG.js → approval-DWQlDPbY.js} +102 -16
- package/dist/arc-8U_6NQWm.js +130 -0
- package/dist/architecture-7GRP2DOG-RTw1wpAq.js +4 -0
- package/dist/architectureDiagram-NJMV4G6O-XmmXrJAK.js +7473 -0
- package/dist/array-DQfpQNY8.js +8 -0
- package/dist/blockDiagram-BEXU5L5S-D4yjnCD1.js +2582 -0
- package/dist/browser.d.ts +444 -48
- package/dist/browser.js +1771 -91
- package/dist/c4Diagram-YGBWAQC7-BLmA_JSd.js +3668 -0
- package/dist/channel-CZxxLrG7.js +9 -0
- package/dist/chunk-2Q5K7J3B-Ck03gkFR.js +21 -0
- package/dist/chunk-3FUC2YCW-tr6jmbQf.js +530 -0
- package/dist/chunk-5DYCD2WN-Bt97YGTd.js +58 -0
- package/dist/chunk-5VM5RSS4-BBxa48HL.js +21 -0
- package/dist/chunk-6AEJRKK7-JXK89I-O.js +14 -0
- package/dist/chunk-742MDFTN-CPmgCGwC.js +466 -0
- package/dist/chunk-7INBJB4K-C9jq9o66.js +6552 -0
- package/dist/chunk-7M6MHVWA-BrKCWcR1.js +4894 -0
- package/dist/chunk-7PRAP22T-BHED6GVs.js +95 -0
- package/dist/chunk-DUW6YSOI-DoZj78PO.js +19 -0
- package/dist/chunk-FOHPRMQF-Dkbp819z.js +27189 -0
- package/dist/chunk-GNY47TPC-Bpvq1T49.js +87 -0
- package/dist/chunk-GTNCS2PH-CLmh4I2c.js +686 -0
- package/dist/chunk-GWA4HPMP-B6vN3fkL.js +95 -0
- package/dist/chunk-J5ZVWO5B-Bi_Pcobw.js +26 -0
- package/dist/chunk-JWPE2WC7-D1rC79GS.js +12 -0
- package/dist/chunk-LNGE3PJU-D5OIoe3Z.js +2582 -0
- package/dist/chunk-MBY4JIJT-C34L7a4f.js +2276 -0
- package/dist/chunk-NETBCI7D-Cg84k8N8.js +321 -0
- package/dist/chunk-O7XYJQB3-B6K0KOSL.js +8846 -0
- package/dist/chunk-UA2S7LBM-DxHM29_K.js +612 -0
- package/dist/chunk-WEXAMYUT-Ba6jFWhB.js +33 -0
- package/dist/chunk-XXDRQBXY-DPbSy4kg.js +12 -0
- package/dist/chunk-Y2CYZVJY-U3QOMqrW.js +15 -0
- package/dist/chunk-Z7XXMR3K-oLg1h8F3.js +1038 -0
- package/dist/chunk-ZIGJFQKS-DqEFBuHR.js +2215 -0
- package/dist/classDiagram-v2-NBCMYWYE-BqnOWIUt.js +3845 -0
- package/dist/cose-bilkent-JH36ORCC-C0dTAHVK.js +4270 -0
- package/dist/cynefin-OW5HDTMX-B2QvgEQj.js +4 -0
- package/dist/cynefinDiagram-VND7K2PF-yAWc6Z3W.js +479 -0
- package/dist/cytoscape.esm-C64mRh9B.js +28325 -0
- package/dist/dagre-6A5THRUB-D0w2W27v.js +4816 -0
- package/dist/defaultLocale-B_EoOkSF.js +249 -0
- package/dist/diagram-22UHCM2B-DvgzhUzP.js +6115 -0
- package/dist/diagram-3UASUU5V-DWgUB-ef.js +795 -0
- package/dist/diagram-ATOU4E4O-P1olqwIs.js +553 -0
- package/dist/diagram-CDSNMT55-BUlZuLUe.js +402 -0
- package/dist/diagram-MLGK6HIB-6w5qmkGt.js +186 -0
- package/dist/diagram-MPIPVDR6-DEFiSo8o.js +289 -0
- package/dist/dist-UajCDt3n.js +92 -0
- package/dist/ebnfDiagram-ZINNZB2B-CI8liCfR.js +123 -0
- package/dist/elk-276RUBZZ-3SvW6OAK.js +90034 -0
- package/dist/erDiagram-OPXOYQCR-CPTbKhwP.js +2301 -0
- package/dist/eventmodeling-NTZA5JFV-BlyuqGp0.js +4 -0
- package/dist/flowDiagram-KWPJA3E3-CcUJ6HbV.js +18 -0
- package/dist/ganttDiagram-FUAMR5RP-31UjY0KK.js +3939 -0
- package/dist/{toolSource-C9oNuKmr.js → geometry-wx5ZTYzi.js} +162 -12
- package/dist/gitGraph-4MIJSDKK-ChdVlrk7.js +4 -0
- package/dist/gitGraphDiagram-X574FWY7-DKuxJymB.js +1153 -0
- package/dist/governance.d.ts +3 -3
- package/dist/graphlib-tk9gQYuN.js +4194 -0
- package/dist/{index-B8Tgmpwh.d.ts → index-BiO9_XRk.d.ts} +2 -2
- package/dist/{index-CYLt5u4L.d.ts → index-CjwdZQOS.d.ts} +700 -12
- package/dist/{index-DHopiH_m.d.ts → index-YPd8ZSEa.d.ts} +156 -9
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/info-A6RAGUB7-CxRAt9S9.js +4 -0
- package/dist/infoDiagram-VRGFBTTK-pRspGfjZ.js +25 -0
- package/dist/init-CMOIWdg-.js +16 -0
- package/dist/ishikawaDiagram-OU5B5YK6-DKerAPAg.js +975 -0
- package/dist/journeyDiagram-ZHPQQLJL-C4MK-YO5.js +1227 -0
- package/dist/kanban-definition-PNTS6WVX-BqsZpMXx.js +1244 -0
- package/dist/katex-BcRRvyh_.js +26465 -0
- package/dist/{kind-DaKqLX2F.js → kind-Dc8x0HWz.js} +54 -7
- package/dist/line-LgV8iVMV.js +48 -0
- package/dist/linear-BWKR0Tqd.js +393 -0
- package/dist/linkedDocument-CIuh_Yp0.js +416 -0
- package/dist/mcp.d.ts +2 -2
- package/dist/{memoryArtifactStore-D6dLeY55.js → memoryArtifactStore-Bs7glPqm.js} +14 -0
- package/dist/mermaid-parser.core-pYR5siSx.js +754 -0
- package/dist/mermaid.core-DMtwGCHy.js +1756 -0
- package/dist/mindmap-definition-NLK3R4M7-CXbD-myG.js +1312 -0
- package/dist/node.d.ts +3 -3
- package/dist/node.js +2 -2
- package/dist/{openUiLibrary-b0i7F_oZ.js → openUiLibrary-B7j3rLrm.js} +1 -1
- package/dist/{openUiSpecLang-CLXJEeRU.js → openUiSpecLang-BSYYnjay.js} +1 -1
- package/dist/ordinal-CxA6GHQS.js +84 -0
- package/dist/packet-AYTQ26CC-BOm08cxl.js +4 -0
- package/dist/path-C27Z2Bjv.js +106 -0
- package/dist/pegDiagram-GJSIUBJH-BLGJOewQ.js +115 -0
- package/dist/pie-WAS4IAKB-Dvg7glpk.js +4 -0
- package/dist/pieDiagram-5QR66LMP-laoaV_PB.js +298 -0
- package/dist/quadrantDiagram-O4NWA36T-Db_wFBkT.js +2236 -0
- package/dist/radar-RG4KPBEZ-BZDaTu06.js +4 -0
- package/dist/railroad-74A4TZTK-C-UhjkOy.js +4 -0
- package/dist/railroad-abnf-HS5TGJTU-dUKVA4OS.js +4 -0
- package/dist/railroad-ebnf-LZEXJU2U-DzQumk18.js +4 -0
- package/dist/railroad-peg-WCYAUIDC-B3vvTWed.js +4 -0
- package/dist/railroadDiagram-XR7U4H2S-BY0sTM4X.js +89 -0
- package/dist/requirementDiagram-PLB6GJNP-3rkQfEhs.js +2474 -0
- package/dist/rough.cjs-AmDd_NQk.js +1395 -0
- package/dist/sankeyDiagram-IPEJSGJF-CGAJhyG2.js +3578 -0
- package/dist/sequenceDiagram-PO4LG4MO-9FJjFX06.js +5522 -0
- package/dist/sizeCapture-INFHLROL-D8PWxdOn.js +56 -0
- package/dist/{skillVersionStore-B24Jjjry-BkOk9wI_.d.ts → skillVersionStore-B24Jjjry-BY1H7Krp.d.ts} +1 -1
- package/dist/src-NkhI3UMl.js +2653 -0
- package/dist/stateDiagram-v2-GCMORJYK-B0O3wc1-.js +2715 -0
- package/dist/swimlanes-2SLR337P-D4EOnrpu.js +6637 -0
- package/dist/swimlanesDiagram-TC7HE7FX-BUx29EJ9.js +30 -0
- package/dist/testing.d.ts +2 -1
- package/dist/testing.js +1 -1
- package/dist/timeline-definition-EJHVYXUP-CrgiiB4C.js +1513 -0
- package/dist/treeView-Q6P3EWNA-C1by-Gzc.js +4 -0
- package/dist/treemap-WGGIJYW6-mC2NZ6ad.js +4 -0
- package/dist/{types-BvTV_05--BW8zDuEk.d.ts → types-CpDRZ0rA-BM5FI9oN.d.ts} +59 -8
- package/dist/ui-react.d.ts +3 -3
- package/dist/ui-react.js +3718 -77
- package/dist/ui-vue.d.ts +1 -1
- package/dist/ui.d.ts +3 -3
- package/dist/ui.js +2 -2
- package/dist/usecaseDiagram-POWQR4AR-BUt_TQOY.js +14397 -0
- package/dist/vennDiagram-UO4OBE2U-CwXr0wjA.js +2808 -0
- package/dist/wardley-WFR3VGLG-CVSYjq_S.js +4 -0
- package/dist/wardleyDiagram-VNRHLVJA-Cpfd47dQ.js +874 -0
- package/dist/{webSkillApi-Cib6G-94.js → webSkillApi-Dy-Zjv0y.js} +1 -1
- package/dist/{webskillLitCatalog-W06npwej.js → webskillLitCatalog-D5BCiMCU.js} +1 -1
- package/dist/xychartDiagram-PMCCYNJV-e1TeVoc6.js +2704 -0
- package/package.json +1 -1
- package/dist/linkedDocument-C0gj1sMq.js +0 -245
package/package.json
CHANGED
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { t as WebSkillError } from "./errors-BDZNpC13.js";
|
|
2
|
-
import writeXlsxFile from "write-excel-file/universal";
|
|
3
|
-
|
|
4
|
-
//#region ../runtime/src/tools/types.ts
|
|
5
|
-
/**
|
|
6
|
-
* 参与 `toolResultMaxBytes` 截断的分片类型(FR-23.3)。**判据的单一来源。**
|
|
7
|
-
*
|
|
8
|
-
* 白名单而不是黑名单:黑名单式下新加的分片默认「参与截断」,
|
|
9
|
-
* 漏改一处就会把一份 PDF 截成坏文件、把 docx 文本腰斩,而且没有任何报错。
|
|
10
|
-
* 白名单式下新分片默认**不参与**,要受文本预算约束必须显式加进来。
|
|
11
|
-
* @experimental
|
|
12
|
-
*/
|
|
13
|
-
const TEXT_BUDGETED_CONTENT_TYPES = /* @__PURE__ */ new Set(["text", "json"]);
|
|
14
|
-
/**
|
|
15
|
-
* `file` 分片的上限(FR-23.4),量的是**实际上线的 base64 长度**而不是解码后的字节——
|
|
16
|
-
* provider 的限额算的是请求载荷。
|
|
17
|
-
*
|
|
18
|
-
* 2026-08-14 查证的三家上限:
|
|
19
|
-
* | provider | 上限 | 出处 |
|
|
20
|
-
* | --------- | --------------------------------------- | ----------------------- |
|
|
21
|
-
* | Anthropic | **32 MB**(**整个请求载荷**)、600 页 | PDF support / 请求大小 |
|
|
22
|
-
* | OpenAI | 单文件 50 MB,全部文件合计 50 MB | File inputs / 使用须知 |
|
|
23
|
-
* | Gemini | 50 MB 或 1000 页(内联与 Files API 同) | 文档理解 / 技术详情 |
|
|
24
|
-
*
|
|
25
|
-
* 取最小值 Anthropic 的 32 MB。它是**整个请求**的额度,不是文档单独的额度,
|
|
26
|
-
* 所以再留出余量给系统提示词、catalog(约 34 KB)、历史消息与其余分片。
|
|
27
|
-
* 25 000 KB base64 ≈ 18.75 MB 原始 PDF。取 1024 的整数倍:设置界面按 KB 展示,
|
|
28
|
-
* 十进制的 24 000 000 会显示成 23437.5 这种读不出来的数。
|
|
29
|
-
*/
|
|
30
|
-
const DEFAULT_MAX_DOCUMENT_BYTES = 256e5;
|
|
31
|
-
/**
|
|
32
|
-
* `document-text` 分片的上限(FR-23.4)。
|
|
33
|
-
*
|
|
34
|
-
* 约束来自**上下文窗口**而不是请求大小:抽出来的文本要整段进上下文。
|
|
35
|
-
* 按英文约 4 字节/token 折算,500 KB ≈ 128K token,占 200K 窗口的多半,
|
|
36
|
-
* 给历史消息与模型的回答留下其余。
|
|
37
|
-
*/
|
|
38
|
-
const DEFAULT_MAX_DOCUMENT_TEXT_BYTES = 512e3;
|
|
39
|
-
/**
|
|
40
|
-
* 单次 fetchData 结果的字节上限(分册 16,FR-16.6):1000 KB。
|
|
41
|
-
* 结构化数据不是文档,量级差一个数量级;超出**只拒不截**——截断的 JSON 解不出来。
|
|
42
|
-
*/
|
|
43
|
-
const DEFAULT_MAX_DATA_SOURCE_BYTES = 1024e3;
|
|
44
|
-
/**
|
|
45
|
-
* 单个上传文件交给脚本的字节上限(0.15.0 分册 17,FR-17.5):20 MB。
|
|
46
|
-
* 取得比模型图片预算宽:字节不进模型上下文,只进脚本,护的是内存不是 token。
|
|
47
|
-
*/
|
|
48
|
-
const DEFAULT_MAX_UPLOAD_FILE_BYTES = 20 * 1024 * 1024;
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region ../runtime/src/spreadsheet/types.ts
|
|
52
|
-
/** 规模上限(FR-10.7)。越界一律 `VALIDATION_FAILED`,不静默截断 */
|
|
53
|
-
const SPREADSHEET_LIMITS = {
|
|
54
|
-
sheets: 16,
|
|
55
|
-
rowsPerSheet: 1e4,
|
|
56
|
-
columnsPerSheet: 256,
|
|
57
|
-
/** Excel 对单个单元格文本的硬限制 */
|
|
58
|
-
charsPerCell: 32767,
|
|
59
|
-
bytes: 16 * 1024 * 1024
|
|
60
|
-
};
|
|
61
|
-
const SPREADSHEET_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
62
|
-
const SPREADSHEET_EXTENSION = ".xlsx";
|
|
63
|
-
/**
|
|
64
|
-
* 本版**不支持**的 xlsx 能力(FR-10.8,备案 D75)。
|
|
65
|
-
*
|
|
66
|
-
* 导出这张表是为了让上层能如实向用户/模型声明缺什么,而不是笼统写「基础支持」——
|
|
67
|
-
* 与 `XLSX_UNEXTRACTED` 同一条口径。
|
|
68
|
-
*/
|
|
69
|
-
const XLSX_UNSUPPORTED = [
|
|
70
|
-
"cell-styles",
|
|
71
|
-
"fonts-and-colors",
|
|
72
|
-
"borders",
|
|
73
|
-
"formulas",
|
|
74
|
-
"merged-cells",
|
|
75
|
-
"charts",
|
|
76
|
-
"images",
|
|
77
|
-
"comments",
|
|
78
|
-
"date-and-time-cell-types",
|
|
79
|
-
"column-widths",
|
|
80
|
-
"frozen-panes",
|
|
81
|
-
"auto-filter",
|
|
82
|
-
"incremental-edit-of-existing-file"
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region ../runtime/src/spreadsheet/encodeSpreadsheet.ts
|
|
87
|
-
/** Excel 不允许出现在工作表名里的字符 */
|
|
88
|
-
const ILLEGAL_SHEET_NAME_CHARS = /[:\\/?*[\]]/;
|
|
89
|
-
const MAX_SHEET_NAME_LENGTH = 31;
|
|
90
|
-
function invalid(message) {
|
|
91
|
-
return new WebSkillError("VALIDATION_FAILED", message);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 把一个 `SpreadsheetCell` 映射成库的输入。
|
|
95
|
-
*
|
|
96
|
-
* **必须显式传 `type`**:裸值会让库自己推断类型,虽然实测 `'0123'` 恰好推断正确,
|
|
97
|
-
* 但那是库的实现细节不是它的契约,而 FR-10.2a 要求「不做智能识别」。
|
|
98
|
-
*
|
|
99
|
-
* `''` 在这里归一成 `null`(DV-3):xlsx 里「空文本」与「空单元格」产出的字节
|
|
100
|
-
* 完全相同,归一让下游只有一条路径。
|
|
101
|
-
*/
|
|
102
|
-
function toCell(value) {
|
|
103
|
-
if (value === null || value === void 0 || value === "") return null;
|
|
104
|
-
if (typeof value === "string") return {
|
|
105
|
-
value,
|
|
106
|
-
type: String
|
|
107
|
-
};
|
|
108
|
-
if (typeof value === "number") return {
|
|
109
|
-
value,
|
|
110
|
-
type: Number
|
|
111
|
-
};
|
|
112
|
-
return {
|
|
113
|
-
value,
|
|
114
|
-
type: Boolean
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function assertSheetName(name, index, seen) {
|
|
118
|
-
if (typeof name !== "string" || name === "") throw invalid(`Sheet ${index + 1}: "name" must be a non-empty string.`);
|
|
119
|
-
if (name.length > MAX_SHEET_NAME_LENGTH) throw invalid(`Sheet "${name}" has a name of ${name.length} characters (max ${MAX_SHEET_NAME_LENGTH}); Excel would refuse to open the file.`);
|
|
120
|
-
if (ILLEGAL_SHEET_NAME_CHARS.test(name)) throw invalid(`Sheet "${name}" has a name containing one of : \\ / ? * [ ], which Excel does not allow.`);
|
|
121
|
-
const key = name.toLowerCase();
|
|
122
|
-
const previous = seen.get(key);
|
|
123
|
-
if (previous !== void 0) throw invalid(`Sheet "${name}" duplicates the name of sheet ${previous + 1}; Excel requires unique sheet names.`);
|
|
124
|
-
seen.set(key, index);
|
|
125
|
-
return name;
|
|
126
|
-
}
|
|
127
|
-
function assertCell(value, sheetName, row, column) {
|
|
128
|
-
if (value === null || value === void 0) return;
|
|
129
|
-
if (typeof value === "number") {
|
|
130
|
-
if (!Number.isFinite(value)) throw invalid(`Sheet "${sheetName}" row ${row} column ${column}: value must be a finite number.`);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (typeof value === "string") {
|
|
134
|
-
if (value.length > SPREADSHEET_LIMITS.charsPerCell) throw invalid(`Sheet "${sheetName}" row ${row} column ${column}: text is ${value.length} characters (max ${SPREADSHEET_LIMITS.charsPerCell}).`);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (typeof value === "boolean") return;
|
|
138
|
-
throw invalid(`Sheet "${sheetName}" row ${row} column ${column}: cell must be a string, number, boolean or null (got ${typeof value}).`);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 全量校验(FR-10.7)。**在映射与编码之前一次查完**,抛第一个越界项的定位。
|
|
142
|
-
*
|
|
143
|
-
* 不做边查边编码:编码到一半才失败会留下一个已经开始的 Blob,
|
|
144
|
-
* 而且用户看到的错误顺序取决于内部遍历顺序,不稳定。
|
|
145
|
-
*/
|
|
146
|
-
function assertSpec(spec) {
|
|
147
|
-
const sheets = spec?.sheets;
|
|
148
|
-
if (!Array.isArray(sheets) || sheets.length === 0) throw invalid("Spreadsheet must contain at least one sheet.");
|
|
149
|
-
if (sheets.length > SPREADSHEET_LIMITS.sheets) throw invalid(`Spreadsheet has ${sheets.length} sheets (max ${SPREADSHEET_LIMITS.sheets}).`);
|
|
150
|
-
const seen = /* @__PURE__ */ new Map();
|
|
151
|
-
sheets.forEach((sheet, index) => {
|
|
152
|
-
const name = assertSheetName(sheet?.name, index, seen);
|
|
153
|
-
const { columns, rows } = sheet;
|
|
154
|
-
if (columns !== void 0 && !Array.isArray(columns)) throw invalid(`Sheet "${name}": "columns" must be an array of header strings when present.`);
|
|
155
|
-
if (!Array.isArray(rows)) throw invalid(`Sheet "${name}": "rows" must be an array of rows.`);
|
|
156
|
-
if (rows.length > SPREADSHEET_LIMITS.rowsPerSheet) throw invalid(`Sheet "${name}" exceeds the row limit: ${rows.length} rows (max ${SPREADSHEET_LIMITS.rowsPerSheet}).`);
|
|
157
|
-
const widest = rows.reduce((max, row) => Math.max(max, Array.isArray(row) ? row.length : 0), columns?.length ?? 0);
|
|
158
|
-
if (widest > SPREADSHEET_LIMITS.columnsPerSheet) throw invalid(`Sheet "${name}" exceeds the column limit: ${widest} columns (max ${SPREADSHEET_LIMITS.columnsPerSheet}).`);
|
|
159
|
-
const headerOffset = columns === void 0 ? 0 : 1;
|
|
160
|
-
columns?.forEach((header, column) => assertCell(header, name, 1, column + 1));
|
|
161
|
-
rows.forEach((row, rowIndex) => {
|
|
162
|
-
if (!Array.isArray(row)) throw invalid(`Sheet "${name}" row ${rowIndex + 1 + headerOffset}: row must be an array of cells.`);
|
|
163
|
-
row.forEach((cell, column) => assertCell(cell, name, rowIndex + 1 + headerOffset, column + 1));
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
return sheets;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* 表头行。加粗写死在这里,**不向调用方暴露任何样式入参**——
|
|
170
|
-
* D75 延后的是样式 API,不是「产出的文件里一个样式属性都不许有」:
|
|
171
|
-
* 表头不加粗的表格在 Excel 里看不出哪行是表头。
|
|
172
|
-
*/
|
|
173
|
-
function headerRow(columns) {
|
|
174
|
-
return columns.map((header) => {
|
|
175
|
-
const cell = toCell(header);
|
|
176
|
-
return cell === null ? null : {
|
|
177
|
-
...cell,
|
|
178
|
-
fontWeight: "bold"
|
|
179
|
-
};
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* 把表格规格编码为 xlsx 字节。
|
|
184
|
-
*
|
|
185
|
-
* 纯函数——不认识产物、run 与工具,因此工具、脚本能力、测试三个消费面共用同一份
|
|
186
|
-
* 实现,AC-10.8「双消费面逐字节相同」是结构性成立的。
|
|
187
|
-
*/
|
|
188
|
-
async function encodeSpreadsheet(spec) {
|
|
189
|
-
const blob = await writeXlsxFile(assertSpec(spec).map((sheet) => ({
|
|
190
|
-
sheet: sheet.name,
|
|
191
|
-
data: [...sheet.columns === void 0 ? [] : [headerRow(sheet.columns)], ...sheet.rows.map((row) => row.map(toCell))]
|
|
192
|
-
}))).toBlob();
|
|
193
|
-
const bytes = new Uint8Array(await blob.arrayBuffer());
|
|
194
|
-
if (bytes.length > SPREADSHEET_LIMITS.bytes) throw invalid(`The encoded spreadsheet is ${bytes.length} bytes (max ${SPREADSHEET_LIMITS.bytes}); reduce the number of rows or sheets.`);
|
|
195
|
-
return bytes;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region ../runtime/src/tools/linkedDocument.ts
|
|
200
|
-
const READ_LINKED_DOCUMENT_TOOL_NAME = "read_linked_document";
|
|
201
|
-
/**
|
|
202
|
-
* 能直接给模型用的 MIME。其余一律拒绝并列出这份清单——
|
|
203
|
-
* 「尽力而为地猜格式」会让模型收到乱码却以为读成功了。
|
|
204
|
-
*/
|
|
205
|
-
const SUPPORTED_DOCUMENT_MIME = {
|
|
206
|
-
pdf: "application/pdf",
|
|
207
|
-
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
208
|
-
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
209
|
-
};
|
|
210
|
-
/** 引擎侧固定流程(§2.3)用到的错误文案,集中一处便于判据引用 */
|
|
211
|
-
const UNSUPPORTED_DOCUMENT_MESSAGE = `Only PDF (${SUPPORTED_DOCUMENT_MIME.pdf}), Word (${SUPPORTED_DOCUMENT_MIME.docx}), Excel (${SUPPORTED_DOCUMENT_MIME.xlsx}) and plain text documents can be read.`;
|
|
212
|
-
const READ_LINKED_DOCUMENT_INPUT_SCHEMA = {
|
|
213
|
-
type: "object",
|
|
214
|
-
properties: { url: {
|
|
215
|
-
type: "string",
|
|
216
|
-
description: "The href of a link that appeared in a perceive_page result."
|
|
217
|
-
} },
|
|
218
|
-
required: ["url"]
|
|
219
|
-
};
|
|
220
|
-
/**
|
|
221
|
-
* 内建工具:读页面链接指向的文档。
|
|
222
|
-
*
|
|
223
|
-
* **始终注册**(只要宿主装配了 reader):docx / xlsx 与纯文本这条路对所有模型成立。
|
|
224
|
-
* PDF 目标在模型不支持文档时**取数后拒绝**,而不是入口就拦 ——
|
|
225
|
-
* 入口拦会误伤 docx,它抽成文本后根本不需要文档能力。
|
|
226
|
-
*/
|
|
227
|
-
const READ_LINKED_DOCUMENT_TOOL = {
|
|
228
|
-
name: READ_LINKED_DOCUMENT_TOOL_NAME,
|
|
229
|
-
description: "Read a document linked from the current page. Pass the exact \"href\" from a perceive_page result. Cross-origin documents need the user to confirm each time.",
|
|
230
|
-
inputSchema: READ_LINKED_DOCUMENT_INPUT_SCHEMA,
|
|
231
|
-
source: "builtin"
|
|
232
|
-
};
|
|
233
|
-
/** 二进制转 base64;`btoa` 只吃 latin1,必须逐字节喂而不是先 decode 成字符串 */
|
|
234
|
-
function toBase64(bytes) {
|
|
235
|
-
let binary = "";
|
|
236
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
237
|
-
return btoa(binary);
|
|
238
|
-
}
|
|
239
|
-
/** `toBase64` 的逆;分片里的文档要交回抽取器时用(0.13.0 FR-22.3) */
|
|
240
|
-
function fromBase64(data) {
|
|
241
|
-
return Uint8Array.from(atob(data), (char) => char.charCodeAt(0));
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
//#endregion
|
|
245
|
-
export { fromBase64 as a, SPREADSHEET_EXTENSION as c, XLSX_UNSUPPORTED as d, DEFAULT_MAX_DATA_SOURCE_BYTES as f, TEXT_BUDGETED_CONTENT_TYPES as g, DEFAULT_MAX_UPLOAD_FILE_BYTES as h, UNSUPPORTED_DOCUMENT_MESSAGE as i, SPREADSHEET_LIMITS as l, DEFAULT_MAX_DOCUMENT_TEXT_BYTES as m, READ_LINKED_DOCUMENT_TOOL_NAME as n, toBase64 as o, DEFAULT_MAX_DOCUMENT_BYTES as p, SUPPORTED_DOCUMENT_MIME as r, encodeSpreadsheet as s, READ_LINKED_DOCUMENT_TOOL as t, SPREADSHEET_MIME_TYPE as u };
|