@tita-agent/dsh-data-table 0.0.0-stage → 0.2.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 (267) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +172 -2
  3. package/cordis.patch.yml +7 -0
  4. package/lib/client.js +16766 -0
  5. package/lib/contract-envelope.d.ts +91 -0
  6. package/lib/contract-envelope.js +106 -0
  7. package/lib/contract-layout.d.ts +130 -0
  8. package/lib/contract-layout.js +138 -0
  9. package/lib/contract-refs.d.ts +39 -0
  10. package/lib/contract-refs.js +9 -0
  11. package/lib/contract-version.d.ts +311 -0
  12. package/lib/contract-version.js +270 -0
  13. package/lib/contract-wire.d.ts +147 -0
  14. package/lib/contract-wire.js +99 -0
  15. package/lib/contracts.d.ts +12 -0
  16. package/lib/contracts.js +12 -0
  17. package/lib/types/audit.d.ts +42 -0
  18. package/lib/types/audit.js +39 -0
  19. package/lib/types/client/ProjectImportMenu.d.ts +30 -0
  20. package/lib/types/client/ProjectImportMenu.js +70 -0
  21. package/lib/types/client/SheetPanel.d.ts +33 -0
  22. package/lib/types/client/SheetPanel.js +1766 -0
  23. package/lib/types/client/SheetToggle.d.ts +18 -0
  24. package/lib/types/client/SheetToggle.js +26 -0
  25. package/lib/types/client/index.d.ts +15 -0
  26. package/lib/types/client/index.js +110 -0
  27. package/lib/types/client/persistence/changes.d.ts +15 -0
  28. package/lib/types/client/persistence/changes.js +51 -0
  29. package/lib/types/client/persistence/ids.d.ts +34 -0
  30. package/lib/types/client/persistence/ids.js +48 -0
  31. package/lib/types/client/persistence/merge.d.ts +35 -0
  32. package/lib/types/client/persistence/merge.js +362 -0
  33. package/lib/types/client/store.d.ts +61 -0
  34. package/lib/types/client/store.js +152 -0
  35. package/lib/types/client/surface-context.d.ts +27 -0
  36. package/lib/types/client/surface-context.js +104 -0
  37. package/lib/types/client/surface-control.d.ts +2 -0
  38. package/lib/types/client/surface-control.js +12 -0
  39. package/lib/types/client/transport/workbookApi.d.ts +159 -0
  40. package/lib/types/client/transport/workbookApi.js +246 -0
  41. package/lib/types/client/univer/StandaloneWorkbookPage.d.ts +5 -0
  42. package/lib/types/client/univer/StandaloneWorkbookPage.js +7 -0
  43. package/lib/types/client/univer/WorkbookCanvas.d.ts +40 -0
  44. package/lib/types/client/univer/WorkbookCanvas.js +87 -0
  45. package/lib/types/client/univer/WorkbookView.d.ts +3 -0
  46. package/lib/types/client/univer/WorkbookView.js +2 -0
  47. package/lib/types/client/univer/loader.d.ts +18 -0
  48. package/lib/types/client/univer/loader.js +81 -0
  49. package/lib/types/client/univer/standalone-entry.d.ts +1 -0
  50. package/lib/types/client/univer/standalone-entry.js +19 -0
  51. package/lib/types/client/versions/VersionChrome.d.ts +33 -0
  52. package/lib/types/client/versions/VersionChrome.js +21 -0
  53. package/lib/types/client/versions/inspect.d.ts +70 -0
  54. package/lib/types/client/versions/inspect.js +88 -0
  55. package/lib/types/client/versions/preview-decoration.d.ts +11 -0
  56. package/lib/types/client/versions/preview-decoration.js +54 -0
  57. package/lib/types/client/versions/records.d.ts +19 -0
  58. package/lib/types/client/versions/records.js +70 -0
  59. package/lib/types/client/workspace-host.d.ts +61 -0
  60. package/lib/types/client/workspace-host.js +124 -0
  61. package/lib/types/collaboration-hub.d.ts +31 -0
  62. package/lib/types/collaboration-hub.js +69 -0
  63. package/lib/types/contract/ids.d.ts +24 -0
  64. package/lib/types/contract/ids.js +46 -0
  65. package/lib/types/contract/mutations.d.ts +25 -0
  66. package/lib/types/contract/mutations.js +782 -0
  67. package/lib/types/contract/operations.d.ts +54 -0
  68. package/lib/types/contract/operations.js +203 -0
  69. package/lib/types/contract/snapshots.d.ts +176 -0
  70. package/lib/types/contract/snapshots.js +351 -0
  71. package/lib/types/contract/univer-api-catalog.d.ts +29 -0
  72. package/lib/types/contract/univer-api-catalog.js +264 -0
  73. package/lib/types/errors.d.ts +8 -0
  74. package/lib/types/errors.js +12 -0
  75. package/lib/types/http/assets-routes.d.ts +3 -0
  76. package/lib/types/http/assets-routes.js +169 -0
  77. package/lib/types/http/collaboration.d.ts +10 -0
  78. package/lib/types/http/collaboration.js +154 -0
  79. package/lib/types/http/history.d.ts +15 -0
  80. package/lib/types/http/history.js +134 -0
  81. package/lib/types/http/project-files.d.ts +79 -0
  82. package/lib/types/http/project-files.js +206 -0
  83. package/lib/types/http/project-scope.d.ts +50 -0
  84. package/lib/types/http/project-scope.js +52 -0
  85. package/lib/types/http/routes.d.ts +98 -0
  86. package/lib/types/http/routes.js +323 -0
  87. package/lib/types/http/standalone.d.ts +9 -0
  88. package/lib/types/http/standalone.js +31 -0
  89. package/lib/types/http/trunk.d.ts +10 -0
  90. package/lib/types/http/trunk.js +322 -0
  91. package/lib/types/http/worktree.d.ts +9 -0
  92. package/lib/types/http/worktree.js +145 -0
  93. package/lib/types/index.d.ts +18 -0
  94. package/lib/types/index.js +156 -0
  95. package/lib/types/invariant.d.ts +15 -0
  96. package/lib/types/invariant.js +15 -0
  97. package/lib/types/request-params.d.ts +21 -0
  98. package/lib/types/request-params.js +76 -0
  99. package/lib/types/store/paths.d.ts +68 -0
  100. package/lib/types/store/paths.js +148 -0
  101. package/lib/types/store/project.d.ts +88 -0
  102. package/lib/types/store/project.js +120 -0
  103. package/lib/types/store/read.d.ts +110 -0
  104. package/lib/types/store/read.js +404 -0
  105. package/lib/types/store/retention.d.ts +27 -0
  106. package/lib/types/store/retention.js +111 -0
  107. package/lib/types/store/write.d.ts +22 -0
  108. package/lib/types/store/write.js +210 -0
  109. package/lib/types/tools/arguments.d.ts +40 -0
  110. package/lib/types/tools/arguments.js +130 -0
  111. package/lib/types/tools/cells.d.ts +50 -0
  112. package/lib/types/tools/cells.js +298 -0
  113. package/lib/types/tools/index.d.ts +2 -0
  114. package/lib/types/tools/index.js +250 -0
  115. package/lib/types/tools/render.d.ts +47 -0
  116. package/lib/types/tools/render.js +290 -0
  117. package/lib/types/tools/univer-api.d.ts +18 -0
  118. package/lib/types/tools/univer-api.js +198 -0
  119. package/lib/types/tools/workbook-catalog.d.ts +3 -0
  120. package/lib/types/tools/workbook-catalog.js +83 -0
  121. package/lib/types/tools/workbook-edit.d.ts +192 -0
  122. package/lib/types/tools/workbook-edit.js +912 -0
  123. package/lib/types/tools/workbook-find.d.ts +11 -0
  124. package/lib/types/tools/workbook-find.js +89 -0
  125. package/lib/types/tools/workbook-history.d.ts +2 -0
  126. package/lib/types/tools/workbook-history.js +59 -0
  127. package/lib/types/tools/workbook-read.d.ts +21 -0
  128. package/lib/types/tools/workbook-read.js +204 -0
  129. package/lib/types/types.d.ts +377 -0
  130. package/lib/types/types.js +34 -0
  131. package/lib/types/univer/apply-operation.d.ts +14 -0
  132. package/lib/types/univer/apply-operation.js +398 -0
  133. package/lib/types/univer/chunk.d.ts +68 -0
  134. package/lib/types/univer/chunk.js +16 -0
  135. package/lib/types/univer/decoration.d.ts +34 -0
  136. package/lib/types/univer/decoration.js +88 -0
  137. package/lib/types/univer/diagnostics.d.ts +31 -0
  138. package/lib/types/univer/diagnostics.js +141 -0
  139. package/lib/types/univer/engine.d.ts +33 -0
  140. package/lib/types/univer/engine.js +338 -0
  141. package/lib/types/univer/entry.d.ts +8 -0
  142. package/lib/types/univer/entry.js +11 -0
  143. package/lib/types/univer/facade.d.ts +107 -0
  144. package/lib/types/univer/facade.js +1 -0
  145. package/lib/types/univer/fonts.d.ts +202 -0
  146. package/lib/types/univer/fonts.js +140 -0
  147. package/lib/types/univer/plugins/collaboration.d.ts +23 -0
  148. package/lib/types/univer/plugins/collaboration.js +47 -0
  149. package/lib/types/univer/plugins/export.d.ts +39 -0
  150. package/lib/types/univer/plugins/export.js +246 -0
  151. package/lib/types/univer/plugins/history.d.ts +24 -0
  152. package/lib/types/univer/plugins/history.js +50 -0
  153. package/lib/types/univer/plugins/version.d.ts +13 -0
  154. package/lib/types/univer/plugins/version.js +13 -0
  155. package/lib/types/version/diff.d.ts +36 -0
  156. package/lib/types/version/diff.js +156 -0
  157. package/lib/types/version/grouping.d.ts +7 -0
  158. package/lib/types/version/grouping.js +94 -0
  159. package/lib/types/version/records.d.ts +17 -0
  160. package/lib/types/version/records.js +102 -0
  161. package/lib/types/version/session.d.ts +36 -0
  162. package/lib/types/version/session.js +89 -0
  163. package/lib/types/version/summary.d.ts +24 -0
  164. package/lib/types/version/summary.js +111 -0
  165. package/lib/types/workbook-manager.d.ts +191 -0
  166. package/lib/types/workbook-manager.js +935 -0
  167. package/lib/types/xlsx-export-worker.d.ts +5 -0
  168. package/lib/types/xlsx-export-worker.js +24 -0
  169. package/lib/types/xlsx-export.d.ts +21 -0
  170. package/lib/types/xlsx-export.js +371 -0
  171. package/lib/types/xlsx-import-worker.d.ts +1 -0
  172. package/lib/types/xlsx-import-worker.js +19 -0
  173. package/lib/univer-client.js +690 -0
  174. package/lib/workbook-page.js +23826 -0
  175. package/lib/xlsx-export-worker.js +104 -0
  176. package/lib/xlsx-import-worker.js +46 -0
  177. package/package.json +106 -3
  178. package/src/audit.ts +58 -0
  179. package/src/client/ProjectImportMenu.tsx +100 -0
  180. package/src/client/SheetPanel.module.css +1578 -0
  181. package/src/client/SheetPanel.tsx +1934 -0
  182. package/src/client/SheetToggle.module.css +73 -0
  183. package/src/client/SheetToggle.tsx +65 -0
  184. package/src/client/contract.d.ts +19 -0
  185. package/src/client/index.ts +131 -0
  186. package/src/client/persistence/changes.ts +58 -0
  187. package/src/client/persistence/ids.ts +60 -0
  188. package/src/client/persistence/merge.ts +392 -0
  189. package/src/client/store.ts +188 -0
  190. package/src/client/surface-context.ts +123 -0
  191. package/src/client/surface-control.ts +13 -0
  192. package/src/client/transport/workbookApi.ts +355 -0
  193. package/src/client/univer/SheetView.module.css +110 -0
  194. package/src/client/univer/StandaloneWorkbookPage.module.css +8 -0
  195. package/src/client/univer/StandaloneWorkbookPage.tsx +15 -0
  196. package/src/client/univer/WorkbookCanvas.tsx +128 -0
  197. package/src/client/univer/WorkbookView.module.css +30 -0
  198. package/src/client/univer/WorkbookView.tsx +3 -0
  199. package/src/client/univer/loader.ts +90 -0
  200. package/src/client/univer/react-dom-client.d.ts +10 -0
  201. package/src/client/univer/standalone-entry.tsx +19 -0
  202. package/src/client/univer/standalone.css +12 -0
  203. package/src/client/univer/univer-locales.d.ts +89 -0
  204. package/src/client/univer/univer-modules.d.ts +26 -0
  205. package/src/client/versions/VersionChrome.tsx +114 -0
  206. package/src/client/versions/inspect.ts +138 -0
  207. package/src/client/versions/preview-decoration.ts +54 -0
  208. package/src/client/versions/records.ts +78 -0
  209. package/src/client/workspace-host.ts +147 -0
  210. package/src/collaboration-hub.ts +83 -0
  211. package/src/contract/ids.ts +50 -0
  212. package/src/contract/mutations.ts +791 -0
  213. package/src/contract/operations.ts +221 -0
  214. package/src/contract/snapshots.ts +383 -0
  215. package/src/contract/univer-api-catalog.ts +289 -0
  216. package/src/css-modules.d.ts +6 -0
  217. package/src/errors.ts +25 -0
  218. package/src/http/assets-routes.ts +177 -0
  219. package/src/http/collaboration.ts +144 -0
  220. package/src/http/history.ts +151 -0
  221. package/src/http/project-files.ts +227 -0
  222. package/src/http/project-scope.ts +77 -0
  223. package/src/http/routes.ts +364 -0
  224. package/src/http/standalone.ts +32 -0
  225. package/src/http/trunk.ts +322 -0
  226. package/src/http/worktree.ts +119 -0
  227. package/src/index.ts +165 -0
  228. package/src/invariant.ts +17 -0
  229. package/src/request-params.ts +92 -0
  230. package/src/store/paths.ts +165 -0
  231. package/src/store/project.ts +137 -0
  232. package/src/store/read.ts +454 -0
  233. package/src/store/retention.ts +106 -0
  234. package/src/store/write.ts +230 -0
  235. package/src/tools/arguments.ts +128 -0
  236. package/src/tools/cells.ts +298 -0
  237. package/src/tools/index.ts +274 -0
  238. package/src/tools/render.ts +301 -0
  239. package/src/tools/univer-api.ts +243 -0
  240. package/src/tools/workbook-catalog.ts +94 -0
  241. package/src/tools/workbook-edit.ts +987 -0
  242. package/src/tools/workbook-find.ts +80 -0
  243. package/src/tools/workbook-history.ts +63 -0
  244. package/src/tools/workbook-read.ts +210 -0
  245. package/src/types.ts +432 -0
  246. package/src/univer/apply-operation.ts +369 -0
  247. package/src/univer/chunk.ts +77 -0
  248. package/src/univer/decoration.ts +111 -0
  249. package/src/univer/diagnostics.ts +136 -0
  250. package/src/univer/engine.ts +370 -0
  251. package/src/univer/entry.ts +14 -0
  252. package/src/univer/facade.ts +91 -0
  253. package/src/univer/fonts.ts +148 -0
  254. package/src/univer/overrides.css +33 -0
  255. package/src/univer/plugins/collaboration.ts +47 -0
  256. package/src/univer/plugins/export.ts +236 -0
  257. package/src/univer/plugins/history.ts +49 -0
  258. package/src/univer/plugins/version.ts +13 -0
  259. package/src/version/diff.ts +169 -0
  260. package/src/version/grouping.ts +96 -0
  261. package/src/version/records.ts +113 -0
  262. package/src/version/session.ts +90 -0
  263. package/src/version/summary.ts +117 -0
  264. package/src/workbook-manager.ts +1111 -0
  265. package/src/xlsx-export-worker.ts +34 -0
  266. package/src/xlsx-export.ts +373 -0
  267. package/src/xlsx-import-worker.ts +30 -0
@@ -0,0 +1,147 @@
1
+ /**
2
+ * 跨插件 HTTP 线协议(wire)。
3
+ *
4
+ * ## 为什么单独一层
5
+ *
6
+ * 契约库里原本放的是「每个插件各自都要用的通用件」——版本模型、磁盘布局、结果信封。
7
+ * HTTP 消费方需要与 table 的目录项、范围响应和单元格样式三个形状保持一致。
8
+ *
9
+ * 手抄的代价不是丑,是**漂移时不报错**:
10
+ *
11
+ * - 消费方写的是防御式解析(`typeof style.ff === 'string'`)。生产者把 `ff` 改名,
12
+ * 消费方不会崩,只是**静默不再画字体**。
13
+ * - 目录响应同理:字段改名后 `Array.isArray(body.workbooks)` 仍然为真,只是每一项
14
+ * 都过不了字段检查,于是**静默显示空列表**。
15
+ *
16
+ * 所以这里把形状定义一次,并且**同时提供类型与校验器**:生产者用它标注返回值(改名 →
17
+ * 编译不过),消费方用它做校验(改名 → 运行时明确报错,而不是降级)。
18
+ *
19
+ * ## 目前的范围
20
+ *
21
+ * Table 提供两条只读工作簿查询路由,供集成调用方读取:
22
+ *
23
+ * ```
24
+ * GET /data-sheet/workbooks.json
25
+ * GET /data-sheet/workbook/{workbookId}/range?sheet=&session=&range=&styles=
26
+ * ```
27
+ *
28
+ * 两条都由 table 生产。
29
+ *
30
+ * ## 不在这一层的东西
31
+ *
32
+ * 统一信封(`./envelope` 的 `Envelope<T,E>`)**没有**覆盖这两条路由,因为它的载荷放在
33
+ * `data` 下,而 table 的响应把载荷放在顶层。把 table 迁到信封等于重写它每一条响应的形状
34
+ * 和它自己的浏览器客户端(`workbookApi.ts`、独立工作簿页),是独立工程。
35
+ * `spec/contracts/envelope.json` 里的「尚未遵守」指的正是这件事,这里不假装它已解决。
36
+ */
37
+ /** 单元格格式。字段名是 Univer 的短码,与 table 的存储格式一致。 */
38
+ export interface SheetCellStyle {
39
+ /** 字体族 */
40
+ ff?: string;
41
+ /** 字号(磅) */
42
+ fs?: number;
43
+ /** 加粗 */
44
+ bl?: boolean;
45
+ /** 斜体 */
46
+ it?: boolean;
47
+ /** 下划线 */
48
+ ul?: boolean;
49
+ /** 删除线 */
50
+ st?: boolean;
51
+ /** 背景色,`#rrggbb` */
52
+ bg?: string;
53
+ /** 前景色,`#rrggbb` */
54
+ cl?: string;
55
+ /** 水平对齐 */
56
+ ht?: number;
57
+ /** 垂直对齐 */
58
+ vt?: number;
59
+ /** 文字旋转 */
60
+ tr?: number;
61
+ /** 数字格式 */
62
+ n?: string;
63
+ }
64
+ /** 一个 0-based、两端 inclusive 的矩形范围。 */
65
+ export interface SheetRangeBounds {
66
+ startRow: number;
67
+ startColumn: number;
68
+ endRow: number;
69
+ endColumn: number;
70
+ }
71
+ /** `GET /data-sheet/workbook/{id}/range` 的 200 响应体。 */
72
+ export interface SheetRangeResponse {
73
+ ok: true;
74
+ workbookId: string;
75
+ workbookName: string;
76
+ /** 读取时的主干修订号;消费方可用来判断是否落后。 */
77
+ revision: number;
78
+ sheetId: string;
79
+ sheetName: string;
80
+ /** 实际返回的范围。请求未指定时是这张表的已用范围。 */
81
+ range: SheetRangeBounds;
82
+ /** 表头行;空表返回空数组而不是一个无名列。 */
83
+ columns: string[];
84
+ /** 数据行(不含表头)。 */
85
+ rows: unknown[][];
86
+ /**
87
+ * 覆盖**整个** `range`(含表头行)的格式矩阵,下标与 `rows` 对齐(`rows[0]` 对应
88
+ * `range.startRow + 1`)。只有请求带 `styles=1` 时才出现。
89
+ */
90
+ styles?: Array<Array<SheetCellStyle | null>>;
91
+ /** 请求的范围窄于已用范围时为 `true`,消费方据此继续取剩余部分。 */
92
+ truncated: boolean;
93
+ }
94
+ /** 目录里一张表的结构摘要。生产者可能带更多字段,消费方只应依赖这些。 */
95
+ export interface WorkbookSheetSchema {
96
+ /** 列定义;对消费方是不透明的,只保证是数组。 */
97
+ columns?: unknown[];
98
+ /** 数据行数,不含表头行。 */
99
+ rowCount?: number;
100
+ }
101
+ /** 目录里的一张表。 */
102
+ export interface WorkbookCatalogSheet {
103
+ id: string;
104
+ name: string;
105
+ schema?: WorkbookSheetSchema;
106
+ }
107
+ /** 目录里的一个工作簿。 */
108
+ export interface WorkbookCatalogEntry {
109
+ id: string;
110
+ name: string;
111
+ /** 主干修订号;消费方可用作乐观并发基线。 */
112
+ revision: number;
113
+ /**
114
+ * 表数量,等于 `sheets.length`。生产者顺手给的冗余字段,消费方不必依赖它。
115
+ * 保留在契约里是因为它**确实在线上**,不写就等于契约漏了一半。
116
+ */
117
+ sheetCount: number;
118
+ /** 最后一次写入时间(ISO 8601)。 */
119
+ updatedAt: string;
120
+ sheets: WorkbookCatalogSheet[];
121
+ }
122
+ /** `GET /data-sheet/workbooks.json` 的 200 响应体。 */
123
+ export interface WorkbookCatalogResponse {
124
+ ok: true;
125
+ workbooks: WorkbookCatalogEntry[];
126
+ }
127
+ /**
128
+ * table 的错误响应体。
129
+ *
130
+ * `code` 只在生产者能给出稳定错误码时出现(例如 `REVISION_CONFLICT`、
131
+ * `VALIDATION_ERROR`);`error` 是给人看的一句话,消费方**不要**用它做判断。
132
+ * 冲突响应还会额外带 `expectedRevision` / `revision` / `conflict`。
133
+ */
134
+ export interface WireErrorBody {
135
+ ok: false;
136
+ code?: string;
137
+ error: string;
138
+ expectedRevision?: number;
139
+ revision?: number;
140
+ conflict?: unknown;
141
+ }
142
+ /** `{ ok: false, error: string }`,忽略额外字段。 */
143
+ export declare function isWireErrorBody(value: unknown): value is WireErrorBody;
144
+ /** 严格校验一个目录响应:任何一项不合格就整体拒绝,而不是悄悄过滤掉。 */
145
+ export declare function isWorkbookCatalogResponse(value: unknown): value is WorkbookCatalogResponse;
146
+ /** 严格校验一个范围响应。 */
147
+ export declare function isSheetRangeResponse(value: unknown): value is SheetRangeResponse;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * 跨插件 HTTP 线协议(wire)。
3
+ *
4
+ * ## 为什么单独一层
5
+ *
6
+ * 契约库里原本放的是「每个插件各自都要用的通用件」——版本模型、磁盘布局、结果信封。
7
+ * HTTP 消费方需要与 table 的目录项、范围响应和单元格样式三个形状保持一致。
8
+ *
9
+ * 手抄的代价不是丑,是**漂移时不报错**:
10
+ *
11
+ * - 消费方写的是防御式解析(`typeof style.ff === 'string'`)。生产者把 `ff` 改名,
12
+ * 消费方不会崩,只是**静默不再画字体**。
13
+ * - 目录响应同理:字段改名后 `Array.isArray(body.workbooks)` 仍然为真,只是每一项
14
+ * 都过不了字段检查,于是**静默显示空列表**。
15
+ *
16
+ * 所以这里把形状定义一次,并且**同时提供类型与校验器**:生产者用它标注返回值(改名 →
17
+ * 编译不过),消费方用它做校验(改名 → 运行时明确报错,而不是降级)。
18
+ *
19
+ * ## 目前的范围
20
+ *
21
+ * Table 提供两条只读工作簿查询路由,供集成调用方读取:
22
+ *
23
+ * ```
24
+ * GET /data-sheet/workbooks.json
25
+ * GET /data-sheet/workbook/{workbookId}/range?sheet=&session=&range=&styles=
26
+ * ```
27
+ *
28
+ * 两条都由 table 生产。
29
+ *
30
+ * ## 不在这一层的东西
31
+ *
32
+ * 统一信封(`./envelope` 的 `Envelope<T,E>`)**没有**覆盖这两条路由,因为它的载荷放在
33
+ * `data` 下,而 table 的响应把载荷放在顶层。把 table 迁到信封等于重写它每一条响应的形状
34
+ * 和它自己的浏览器客户端(`workbookApi.ts`、独立工作簿页),是独立工程。
35
+ * `spec/contracts/envelope.json` 里的「尚未遵守」指的正是这件事,这里不假装它已解决。
36
+ */
37
+ /** 是否为「不是对象」以外的任意值——所有校验器的第一道门。 */
38
+ function isObject(value) {
39
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
40
+ }
41
+ /** `{ ok: false, error: string }`,忽略额外字段。 */
42
+ export function isWireErrorBody(value) {
43
+ return isObject(value) && value.ok === false && typeof value.error === 'string';
44
+ }
45
+ /** 严格校验一个目录响应:任何一项不合格就整体拒绝,而不是悄悄过滤掉。 */
46
+ export function isWorkbookCatalogResponse(value) {
47
+ if (!isObject(value) || value.ok !== true || !Array.isArray(value.workbooks))
48
+ return false;
49
+ return value.workbooks.every(entry => {
50
+ if (!isObject(entry))
51
+ return false;
52
+ if (typeof entry.id !== 'string' || typeof entry.name !== 'string')
53
+ return false;
54
+ if (typeof entry.revision !== 'number' || typeof entry.sheetCount !== 'number')
55
+ return false;
56
+ if (typeof entry.updatedAt !== 'string' || !Array.isArray(entry.sheets))
57
+ return false;
58
+ return entry.sheets.every(sheet => {
59
+ if (!isObject(sheet))
60
+ return false;
61
+ if (typeof sheet.id !== 'string' || typeof sheet.name !== 'string')
62
+ return false;
63
+ if (sheet.schema === undefined)
64
+ return true;
65
+ const schema = sheet.schema;
66
+ if (!isObject(schema))
67
+ return false;
68
+ if (schema.columns !== undefined && !Array.isArray(schema.columns))
69
+ return false;
70
+ return schema.rowCount === undefined || typeof schema.rowCount === 'number';
71
+ });
72
+ });
73
+ }
74
+ /** 严格校验一个范围响应。 */
75
+ export function isSheetRangeResponse(value) {
76
+ if (!isObject(value) || value.ok !== true)
77
+ return false;
78
+ if (typeof value.workbookId !== 'string' || typeof value.sheetName !== 'string')
79
+ return false;
80
+ if (!Array.isArray(value.columns) || !value.columns.every(column => typeof column === 'string'))
81
+ return false;
82
+ if (!Array.isArray(value.rows))
83
+ return false;
84
+ if (typeof value.truncated !== 'boolean')
85
+ return false;
86
+ if (value.styles !== undefined) {
87
+ if (!Array.isArray(value.styles))
88
+ return false;
89
+ if (!value.styles.every(row => Array.isArray(row)))
90
+ return false;
91
+ }
92
+ if (value.range === undefined)
93
+ return false;
94
+ const range = value.range;
95
+ if (!isObject(range))
96
+ return false;
97
+ // 先取出局部常量再进闭包:TS 不会把 `value.range` 的收窄带进回调。
98
+ return ['startRow', 'startColumn', 'endRow', 'endColumn'].every(key => typeof range[key] === 'number');
99
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared wire contracts and pure protocol helpers.
3
+ *
4
+ * This source lives in the existing private UI workspace package so DSH plugins
5
+ * can type-check against one canonical module. Client and host builds bundle the
6
+ * imported code into their plugin output; it is not a published runtime package.
7
+ */
8
+ export * from './contract-envelope.js';
9
+ export * from './contract-refs.js';
10
+ export * from './contract-version.js';
11
+ export * from './contract-layout.js';
12
+ export * from './contract-wire.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared wire contracts and pure protocol helpers.
3
+ *
4
+ * This source lives in the existing private UI workspace package so DSH plugins
5
+ * can type-check against one canonical module. Client and host builds bundle the
6
+ * imported code into their plugin output; it is not a published runtime package.
7
+ */
8
+ export * from './contract-envelope.js';
9
+ export * from './contract-refs.js';
10
+ export * from './contract-version.js';
11
+ export * from './contract-layout.js';
12
+ export * from './contract-wire.js';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Audit lineage (docs/issue/0022 P3).
3
+ *
4
+ * Workbook writes carry who asked for them: the ids the model passed, filled in
5
+ * from the active intent recorder when it is installed. Both transports need
6
+ * this — the browser sends them in a request body, the Agent receives them in
7
+ * tool arguments — so it is neither one's private concern.
8
+ */
9
+ import type { LineageContext } from '#contracts';
10
+ export declare function lineageOfValue(value: unknown): LineageContext | undefined;
11
+ /**
12
+ * Active-recorder lineage supplied by `dsh-data-domain-knowledge`'s intent
13
+ * service (`titaDataAgentIntent`; the module was its own package until 0020).
14
+ * Optional: without the recorder plugin, workbook writes keep carrying only the
15
+ * lineage the model passed explicitly.
16
+ */
17
+ export interface LineageProvider {
18
+ activeLineage(sessionKey: string): {
19
+ lineage: Partial<LineageContext>;
20
+ committed: boolean;
21
+ } | undefined;
22
+ }
23
+ /**
24
+ * The scope the intent recorder is resolved from. `apply()` sets it once; it is
25
+ * module state because the recorder is a host service rather than an argument.
26
+ */
27
+ export declare let lineageScope: {
28
+ get(name: string, strict?: boolean): unknown;
29
+ } | undefined;
30
+ export declare function setLineageScope(scope: {
31
+ get(name: string, strict?: boolean): unknown;
32
+ } | undefined): void;
33
+ export declare function lineageProvider(): LineageProvider | undefined;
34
+ export declare function lineageOfArgs(args: Record<string, unknown>, exec?: {
35
+ agent?: {
36
+ session?: {
37
+ header?: {
38
+ id?: string;
39
+ };
40
+ };
41
+ };
42
+ }): LineageContext | undefined;
@@ -0,0 +1,39 @@
1
+ export function lineageOfValue(value) {
2
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
3
+ return undefined;
4
+ const args = value;
5
+ const lineage = {};
6
+ const fields = [
7
+ ['sessionId', 'sessionId'], ['turnId', 'turnId'], ['intentId', 'intentId'],
8
+ ['taskId', 'taskId'], ['subtaskId', 'subtaskId'], ['parentSubtaskId', 'parentSubtaskId'], ['runId', 'runId'],
9
+ ['traceId', 'traceId'], ['domain', 'domain'],
10
+ ];
11
+ for (const [target, source] of fields)
12
+ if (typeof args[source] === 'string' && args[source].trim())
13
+ lineage[target] = args[source].trim().slice(0, 160);
14
+ return Object.keys(lineage).length > 0 ? lineage : undefined;
15
+ }
16
+ /**
17
+ * The scope the intent recorder is resolved from. `apply()` sets it once; it is
18
+ * module state because the recorder is a host service rather than an argument.
19
+ */
20
+ export let lineageScope;
21
+ export function setLineageScope(scope) {
22
+ lineageScope = scope;
23
+ }
24
+ export function lineageProvider() {
25
+ const scope = lineageScope;
26
+ // Test harnesses pass a minimal context; only a real cordis scope can resolve services.
27
+ if (typeof scope?.get !== 'function')
28
+ return undefined;
29
+ return scope.get('titaDataAgentIntent', false);
30
+ }
31
+ export function lineageOfArgs(args, exec) {
32
+ const lineage = lineageOfValue(args);
33
+ const sessionId = lineage?.sessionId ?? exec?.agent?.session?.header?.id;
34
+ if (!sessionId)
35
+ return lineage;
36
+ // Explicit arguments win; the recorder only fills the ids a call omitted.
37
+ const inherited = lineageProvider()?.activeLineage(sessionId)?.lineage;
38
+ return { sessionId, ...inherited, ...lineage };
39
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The workbook import menu, and the chooser behind it.
3
+ *
4
+ * Import used to start and end in the operating system's file dialog. It now
5
+ * starts in the project: the menu opens a listing of `<project>/storages` with
6
+ * each file's creation and modification time, because a project that keeps its
7
+ * data beside itself should offer its own files first.
8
+ *
9
+ * It is still not a wall. Containment says where a project's files live, not
10
+ * what a user may open, so the chooser's footer keeps "从项目外导入…" — the same
11
+ * OS dialog as before, one click away rather than two.
12
+ *
13
+ * The bytes of a chosen file are read by the Host (a browser cannot open a path),
14
+ * and from there the pipeline is the one that already existed: the buffer goes
15
+ * back as `data-sheet:import-bytes` and `univer/plugins/export.ts` parses it.
16
+ *
17
+ * @module dsh-data-table/client/ProjectImportMenu
18
+ */
19
+ import { type ReactElement } from 'react';
20
+ export interface ProjectImportMenuProps {
21
+ /** True while no workbook is open: importing has nowhere to land. */
22
+ disabled: boolean;
23
+ }
24
+ /**
25
+ * The 导入 menu plus the project file chooser it opens.
26
+ *
27
+ * @param props - See {@link ProjectImportMenuProps}.
28
+ * @returns the menu and, when open, the chooser.
29
+ */
30
+ export declare function ProjectImportMenu({ disabled }: ProjectImportMenuProps): ReactElement;
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The workbook import menu, and the chooser behind it.
4
+ *
5
+ * Import used to start and end in the operating system's file dialog. It now
6
+ * starts in the project: the menu opens a listing of `<project>/storages` with
7
+ * each file's creation and modification time, because a project that keeps its
8
+ * data beside itself should offer its own files first.
9
+ *
10
+ * It is still not a wall. Containment says where a project's files live, not
11
+ * what a user may open, so the chooser's footer keeps "从项目外导入…" — the same
12
+ * OS dialog as before, one click away rather than two.
13
+ *
14
+ * The bytes of a chosen file are read by the Host (a browser cannot open a path),
15
+ * and from there the pipeline is the one that already existed: the buffer goes
16
+ * back as `data-sheet:import-bytes` and `univer/plugins/export.ts` parses it.
17
+ *
18
+ * @module dsh-data-table/client/ProjectImportMenu
19
+ */
20
+ import { useState } from 'react';
21
+ import { FilePickerDialog, ToolbarMenu } from '@tita-agent/ui';
22
+ import { FileSpreadsheet, FileText, Upload } from '@tita-agent/ui/icons';
23
+ import { fetchProjectFiles, readProjectFile } from "./transport/workbookApi.js";
24
+ /** Extensions each format accepts, as the chooser's filter. */
25
+ const ACCEPT = { xlsx: ['.xlsx', '.xls'], csv: ['.csv'] };
26
+ /** Copy for each format, used in the menu hint and the dialog's title. */
27
+ const FORMAT_LABEL = { xlsx: 'Excel', csv: 'CSV' };
28
+ /**
29
+ * The 导入 menu plus the project file chooser it opens.
30
+ *
31
+ * @param props - See {@link ProjectImportMenuProps}.
32
+ * @returns the menu and, when open, the chooser.
33
+ */
34
+ export function ProjectImportMenu({ disabled }) {
35
+ const [format, setFormat] = useState(null);
36
+ /** Hand a chosen file's bytes to the import pipeline. */
37
+ const readAndImport = (entry, chosen) => {
38
+ setFormat(null);
39
+ void readProjectFile(entry.path)
40
+ .then(file => {
41
+ window.dispatchEvent(new CustomEvent('data-sheet:import-bytes', {
42
+ detail: { data: file.data, name: file.name, format: chosen },
43
+ }));
44
+ })
45
+ .catch((error) => {
46
+ // The panel already listens for this event, so a failure to read the
47
+ // file reports itself the same way a failure to parse it does.
48
+ window.dispatchEvent(new CustomEvent('data-sheet:import-error', {
49
+ detail: { message: error instanceof Error ? error.message : String(error) },
50
+ }));
51
+ });
52
+ };
53
+ return (_jsxs(_Fragment, { children: [_jsx(ToolbarMenu, { label: "\u5BFC\u5165", icon: _jsx(Upload, { size: 14, "aria-hidden": "true" }), disabled: disabled, groups: [{
54
+ items: [
55
+ { id: 'xlsx', label: '导入 Excel', hint: '从项目 storages/ 选择文件', icon: _jsx(FileSpreadsheet, { size: 15, "aria-hidden": "true" }), onSelect: () => { setFormat('xlsx'); } },
56
+ { id: 'csv', label: '导入 CSV', hint: '从项目 storages/ 选择文件', icon: _jsx(FileText, { size: 15, "aria-hidden": "true" }), onSelect: () => { setFormat('csv'); } },
57
+ ],
58
+ }] }), format !== null && (_jsx(FilePickerDialog, { open: true, onOpenChange: next => { if (!next)
59
+ setFormat(null); }, title: `导入 ${FORMAT_LABEL[format]} 文件`, description: `选择项目 storages/ 下的文件;内容读入当前工作簿,原文件不会被移动或改动。`, accept: ACCEPT[format], load: fetchProjectFiles, onPick: entry => { readAndImport(entry, format); }, onImportOutside: () => {
60
+ const outside = format;
61
+ setFormat(null);
62
+ // Literal event names rather than a template: the Univer bridge is
63
+ // looked up by these exact strings, and a name assembled at runtime
64
+ // is a bridge nobody can grep for.
65
+ if (outside === 'csv')
66
+ window.dispatchEvent(new CustomEvent('data-sheet:request-import-csv'));
67
+ else
68
+ window.dispatchEvent(new CustomEvent('data-sheet:request-import-xlsx'));
69
+ } }))] }));
70
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Right-column workbook canvas. Univer owns the editing experience; this
3
+ * component owns the browser projection of the DSH workbook service:
4
+ * snapshot bootstrap, incremental user operations, and Agent-operation sync.
5
+ * @module dsh-data-table/client/SheetPanel
6
+ */
7
+ import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
8
+ import type { SurfaceBridgeService } from '@tita-agent/dsh-surface-bridge';
9
+ import '@tita-agent/ui/styles.css';
10
+ type PanelProps = PropsRuntime<'details'>;
11
+ export interface WorkbookWorkspaceProps {
12
+ /** Whether the workspace is live. The embedded pane keeps this true even while parked. */
13
+ open: boolean;
14
+ /**
15
+ * Whether the workspace is on screen. Defaults to `open`.
16
+ *
17
+ * The resident workspace outlives the pane, so `open` cannot answer this; the
18
+ * few behaviours that must follow real visibility (the window-level save
19
+ * shortcut) read this instead.
20
+ */
21
+ visible?: boolean;
22
+ /** Standalone mode removes the in-panel affordances that only make sense in DSH. */
23
+ standalone?: boolean;
24
+ /** Optional workbook to load first; embedded mode otherwise requires explicit selection. */
25
+ initialWorkbookId?: string;
26
+ /** Shared DSH composer context bridge; absent in standalone pages. */
27
+ bridge?: SurfaceBridgeService;
28
+ }
29
+ /** Shared workbook workspace used by both the DSH details panel and the standalone page. */
30
+ export declare function WorkbookWorkspace({ open, visible, standalone, initialWorkbookId, bridge }: WorkbookWorkspaceProps): import("react").JSX.Element;
31
+ /** Right-column adapter: the DSH layout owns the open/close state. */
32
+ export declare function SheetPanel(_: PanelProps): import("react").JSX.Element;
33
+ export {};