dsh-typst-plugin 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 (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +121 -0
  3. package/README.md +120 -2
  4. package/cordis.patch.yml +6 -0
  5. package/docs/images/icon.png +0 -0
  6. package/docs/plugin-detail.en.md +2 -0
  7. package/docs/plugin-detail.md +2 -0
  8. package/lib/client.js +41996 -0
  9. package/lib/client.js.map +7 -0
  10. package/lib/config.d.ts +107 -0
  11. package/lib/config.d.ts.map +1 -0
  12. package/lib/config.js +167 -0
  13. package/lib/config.js.map +1 -0
  14. package/lib/constants.d.ts +77 -0
  15. package/lib/constants.d.ts.map +1 -0
  16. package/lib/constants.js +85 -0
  17. package/lib/constants.js.map +1 -0
  18. package/lib/contract.d.ts +263 -0
  19. package/lib/contract.d.ts.map +1 -0
  20. package/lib/contract.js +9 -0
  21. package/lib/contract.js.map +1 -0
  22. package/lib/diagnostic-text.d.ts +13 -0
  23. package/lib/diagnostic-text.d.ts.map +1 -0
  24. package/lib/diagnostic-text.js +28 -0
  25. package/lib/diagnostic-text.js.map +1 -0
  26. package/lib/errors.d.ts +119 -0
  27. package/lib/errors.d.ts.map +1 -0
  28. package/lib/errors.js +161 -0
  29. package/lib/errors.js.map +1 -0
  30. package/lib/host/facts.d.ts +31 -0
  31. package/lib/host/facts.d.ts.map +1 -0
  32. package/lib/host/facts.js +145 -0
  33. package/lib/host/facts.js.map +1 -0
  34. package/lib/host/which.d.ts +20 -0
  35. package/lib/host/which.d.ts.map +1 -0
  36. package/lib/host/which.js +50 -0
  37. package/lib/host/which.js.map +1 -0
  38. package/lib/index.d.ts +2 -0
  39. package/lib/index.d.ts.map +1 -0
  40. package/lib/index.js +2 -0
  41. package/lib/index.js.map +1 -0
  42. package/lib/remote.d.ts +70 -0
  43. package/lib/remote.d.ts.map +1 -0
  44. package/lib/remote.js +156 -0
  45. package/lib/remote.js.map +1 -0
  46. package/lib/service.d.ts +71 -0
  47. package/lib/service.d.ts.map +1 -0
  48. package/lib/service.js +213 -0
  49. package/lib/service.js.map +1 -0
  50. package/lib/skills/typst.d.ts +13 -0
  51. package/lib/skills/typst.d.ts.map +1 -0
  52. package/lib/skills/typst.js +78 -0
  53. package/lib/skills/typst.js.map +1 -0
  54. package/lib/status-codec.d.ts +11 -0
  55. package/lib/status-codec.d.ts.map +1 -0
  56. package/lib/status-codec.js +11 -0
  57. package/lib/status-codec.js.map +1 -0
  58. package/lib/tools/registration.d.ts +23 -0
  59. package/lib/tools/registration.d.ts.map +1 -0
  60. package/lib/tools/registration.js +758 -0
  61. package/lib/tools/registration.js.map +1 -0
  62. package/lib/tools/shared.d.ts +30 -0
  63. package/lib/tools/shared.d.ts.map +1 -0
  64. package/lib/tools/shared.js +79 -0
  65. package/lib/tools/shared.js.map +1 -0
  66. package/lib/typert.d.ts +25 -0
  67. package/lib/typert.d.ts.map +1 -0
  68. package/lib/typert.js +116 -0
  69. package/lib/typert.js.map +1 -0
  70. package/lib/typst/diagnostics.d.ts +58 -0
  71. package/lib/typst/diagnostics.d.ts.map +1 -0
  72. package/lib/typst/diagnostics.js +237 -0
  73. package/lib/typst/diagnostics.js.map +1 -0
  74. package/lib/typst/flags.d.ts +8 -0
  75. package/lib/typst/flags.d.ts.map +1 -0
  76. package/lib/typst/flags.js +8 -0
  77. package/lib/typst/flags.js.map +1 -0
  78. package/lib/typst/locate.d.ts +61 -0
  79. package/lib/typst/locate.d.ts.map +1 -0
  80. package/lib/typst/locate.js +152 -0
  81. package/lib/typst/locate.js.map +1 -0
  82. package/lib/typst/mainfile.d.ts +40 -0
  83. package/lib/typst/mainfile.d.ts.map +1 -0
  84. package/lib/typst/mainfile.js +136 -0
  85. package/lib/typst/mainfile.js.map +1 -0
  86. package/lib/typst/match.d.ts +67 -0
  87. package/lib/typst/match.d.ts.map +1 -0
  88. package/lib/typst/match.js +227 -0
  89. package/lib/typst/match.js.map +1 -0
  90. package/lib/typst/oneshot.d.ts +48 -0
  91. package/lib/typst/oneshot.d.ts.map +1 -0
  92. package/lib/typst/oneshot.js +86 -0
  93. package/lib/typst/oneshot.js.map +1 -0
  94. package/lib/typst/owners.d.ts +28 -0
  95. package/lib/typst/owners.d.ts.map +1 -0
  96. package/lib/typst/owners.js +98 -0
  97. package/lib/typst/owners.js.map +1 -0
  98. package/lib/typst/pdf-extract.d.ts +28 -0
  99. package/lib/typst/pdf-extract.d.ts.map +1 -0
  100. package/lib/typst/pdf-extract.js +111 -0
  101. package/lib/typst/pdf-extract.js.map +1 -0
  102. package/lib/typst/process.d.ts +73 -0
  103. package/lib/typst/process.d.ts.map +1 -0
  104. package/lib/typst/process.js +147 -0
  105. package/lib/typst/process.js.map +1 -0
  106. package/lib/typst/text.d.ts +62 -0
  107. package/lib/typst/text.d.ts.map +1 -0
  108. package/lib/typst/text.js +282 -0
  109. package/lib/typst/text.js.map +1 -0
  110. package/lib/typst/watcher.d.ts +76 -0
  111. package/lib/typst/watcher.d.ts.map +1 -0
  112. package/lib/typst/watcher.js +210 -0
  113. package/lib/typst/watcher.js.map +1 -0
  114. package/lib/wire-schemas.d.ts +433 -0
  115. package/lib/wire-schemas.d.ts.map +1 -0
  116. package/lib/wire-schemas.js +428 -0
  117. package/lib/wire-schemas.js.map +1 -0
  118. package/lib/workspace/containment.d.ts +25 -0
  119. package/lib/workspace/containment.d.ts.map +1 -0
  120. package/lib/workspace/containment.js +54 -0
  121. package/lib/workspace/containment.js.map +1 -0
  122. package/lib/workspace/session.d.ts +268 -0
  123. package/lib/workspace/session.d.ts.map +1 -0
  124. package/lib/workspace/session.js +1576 -0
  125. package/lib/workspace/session.js.map +1 -0
  126. package/locale/en.json +15 -0
  127. package/locale/zh.json +15 -0
  128. package/package.json +113 -4
  129. package/release-provenance.json +137 -0
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Wire identity shared by both halves: the view types the host serves and
3
+ * the browser half renders, plus the strict zod codecs both arms materialize
4
+ * (`wire-schemas.ts`). Values and type-only imports only — this module is on
5
+ * the client-graph allowlist (`scripts/client-graph-authority.mjs`).
6
+ * @module dsh-typst/contract
7
+ */
8
+ import type { TypstErrorCode } from "./errors.js";
9
+ /**
10
+ * One Remote failure code per stable domain failure: every domain error
11
+ * crosses the wire as its own `typst/<reason>`, so consumers discriminate on
12
+ * `error.code` while `details.code` keeps the host's stable domain code.
13
+ */
14
+ declare module "@deepseek-ai/dsh-typert-protocol" {
15
+ interface RemoteErrorDetailsMap {
16
+ "typst/missing": {
17
+ readonly code: TypstErrorCode;
18
+ };
19
+ "typst/too-old": {
20
+ readonly code: TypstErrorCode;
21
+ };
22
+ "typst/unusable": {
23
+ readonly code: TypstErrorCode;
24
+ };
25
+ "typst/no-main": {
26
+ readonly code: TypstErrorCode;
27
+ };
28
+ "typst/no-preview": {
29
+ readonly code: TypstErrorCode;
30
+ };
31
+ "typst/not-found": {
32
+ readonly code: TypstErrorCode;
33
+ };
34
+ "typst/invalid-argument": {
35
+ readonly code: TypstErrorCode;
36
+ };
37
+ "typst/path-outside-workspace": {
38
+ readonly code: TypstErrorCode;
39
+ };
40
+ "typst/timeout": {
41
+ readonly code: TypstErrorCode;
42
+ };
43
+ "typst/watch-failed": {
44
+ readonly code: TypstErrorCode;
45
+ };
46
+ "typst/quote-not-found": {
47
+ readonly code: TypstErrorCode;
48
+ };
49
+ "typst/not-composed": {
50
+ readonly code: TypstErrorCode;
51
+ };
52
+ "typst/attachment-unavailable": {
53
+ readonly code: TypstErrorCode;
54
+ };
55
+ "typst/compile-failed": {
56
+ readonly code: TypstErrorCode;
57
+ };
58
+ "typst/sandbox-read-only": {
59
+ readonly code: TypstErrorCode;
60
+ };
61
+ "typst/sandbox-invalid-root": {
62
+ readonly code: TypstErrorCode;
63
+ };
64
+ "typst/page-out-of-range": {
65
+ readonly code: TypstErrorCode;
66
+ };
67
+ "typst/main-changed": {
68
+ readonly code: TypstErrorCode;
69
+ };
70
+ "typst/clock-skew": {
71
+ readonly code: TypstErrorCode;
72
+ };
73
+ "typst/invalid-target": {
74
+ readonly code: TypstErrorCode;
75
+ };
76
+ "typst/settle-failed": {
77
+ readonly code: TypstErrorCode;
78
+ };
79
+ "typst/unexpected": {
80
+ readonly code: TypstErrorCode;
81
+ };
82
+ }
83
+ }
84
+ /** Where the located binary came from. */
85
+ export type TypstSource = "setting" | "path" | "common" | "shell";
86
+ export interface ToolchainReadyView {
87
+ state: "ready";
88
+ version: string;
89
+ path: string;
90
+ source: TypstSource;
91
+ }
92
+ export interface ToolchainMissingView {
93
+ state: "missing";
94
+ }
95
+ export interface ToolchainTooOldView {
96
+ state: "too_old";
97
+ version: string;
98
+ path: string;
99
+ source: TypstSource;
100
+ error: string;
101
+ }
102
+ export interface ToolchainErrorView {
103
+ state: "error";
104
+ path?: string;
105
+ source?: TypstSource;
106
+ error: string;
107
+ }
108
+ export type ToolchainView = ToolchainReadyView | ToolchainMissingView | ToolchainTooOldView | ToolchainErrorView;
109
+ export interface DiagnosticLocationView {
110
+ file: string;
111
+ line: number;
112
+ column: number;
113
+ }
114
+ export interface DiagnosticPointView {
115
+ message: string;
116
+ location: DiagnosticLocationView | null;
117
+ }
118
+ export interface DiagnosticView {
119
+ severity: "error" | "warning";
120
+ message: string;
121
+ location: DiagnosticLocationView | null;
122
+ excerpt?: string;
123
+ hints: string[];
124
+ trace: DiagnosticPointView[];
125
+ }
126
+ export type CompilePhase = "idle" | "starting" | "compiling" | "ok" | "warnings" | "error" | "crashed";
127
+ export interface StatusView {
128
+ phase: CompilePhase;
129
+ run: number;
130
+ durationMs?: number;
131
+ error?: string;
132
+ finishedAt?: number;
133
+ }
134
+ /** Metadata of the current preview PDF; bytes ride `readPreview`. */
135
+ export interface PreviewIdentity {
136
+ generation: number;
137
+ seq: number;
138
+ sha256: string;
139
+ }
140
+ export interface SnapshotView extends PreviewIdentity {
141
+ main: string;
142
+ run: number;
143
+ bytes: number;
144
+ pages: number;
145
+ createdAt: number;
146
+ }
147
+ export interface SourceRefView {
148
+ file: string;
149
+ line: number;
150
+ endLine: number;
151
+ }
152
+ /**
153
+ * One agent highlight. Rects are PDF user-space `[x1, y1, x2, y2]` boxes on
154
+ * the page; the panel maps them through the page viewport. `seq` names the
155
+ * snapshot the rects belong to; after a recompile the host re-locates the
156
+ * quote and pushes new rects (unmatched highlights turn `stale`).
157
+ */
158
+ export interface HighlightView {
159
+ id: string;
160
+ quote: string;
161
+ comment: string;
162
+ source?: SourceRefView;
163
+ identity: PreviewIdentity;
164
+ seq: number;
165
+ pageIndex: number;
166
+ /** UTF-16 offset of the matched text on its page, kept for re-location. */
167
+ startOffset?: number;
168
+ /** Ordinal of the quote occurrence in its source file, when created from lines. */
169
+ occurrence?: number;
170
+ rects: number[][];
171
+ stale: boolean;
172
+ createdAt: number;
173
+ }
174
+ /** A location request from `typst_show`; the panel notifies before navigating. */
175
+ export type PanelView = {
176
+ kind: "page";
177
+ pageIndex: number;
178
+ identity: PreviewIdentity;
179
+ } | {
180
+ kind: "highlight";
181
+ id: string;
182
+ identity: PreviewIdentity;
183
+ } | null;
184
+ export interface PackageManagerView {
185
+ name: string;
186
+ version?: string;
187
+ path: string;
188
+ }
189
+ export interface HostFactsView {
190
+ os: "macos" | "windows" | "linux" | "other";
191
+ osName: string;
192
+ arch: string;
193
+ tools: PackageManagerView[];
194
+ }
195
+ export interface SetupView {
196
+ facts: HostFactsView | null;
197
+ searched: string[];
198
+ }
199
+ /** What one explicit index refresh discovered, returned to its caller. */
200
+ export interface DiscoveryView {
201
+ /** Number of `.typ` candidates the refresh left in the workspace index. */
202
+ candidates: number;
203
+ includeExcluded: boolean;
204
+ errors: string[];
205
+ }
206
+ /**
207
+ * Everything the panel renders, in one frame: the stream's first frame is
208
+ * the current state, later frames follow every relevant change (compile
209
+ * finished, snapshot replaced, highlight moved, toolchain changed).
210
+ */
211
+ export interface TypstStateFrame {
212
+ version: number;
213
+ generation: number;
214
+ previewError: string | null;
215
+ discovery: {
216
+ scanning: boolean;
217
+ includeExcluded: boolean;
218
+ visited: number;
219
+ errors: string[];
220
+ };
221
+ toolchain: ToolchainView;
222
+ workspace: string;
223
+ /** Absolute workspace root the diagnostics' relative file paths resolve against. */
224
+ workspaceRoot: string;
225
+ main: string | null;
226
+ candidates: string[];
227
+ /**
228
+ * The candidates this document includes, as typst's own dependency report
229
+ * names them. A fragment is a `.typ` file another file pulls in with
230
+ * `#include` or `#import`; compiling one on its own is rarely what the user
231
+ * means, so the panel lists them apart from other, unclassified files.
232
+ */
233
+ fragments: string[];
234
+ status: StatusView;
235
+ /**
236
+ * Diagnostics of this round, capped at `LIMITS.diagnostics`. When the
237
+ * compiler produced more, `diagnosticsTotal` is the full count and
238
+ * `diagnosticsTruncated` is true; the model text and the panel both show
239
+ * the same bounded views.
240
+ */
241
+ diagnostics: DiagnosticView[];
242
+ diagnosticsTotal: number;
243
+ diagnosticsTruncated: boolean;
244
+ snapshot: SnapshotView | null;
245
+ highlights: HighlightView[];
246
+ view: PanelView;
247
+ viewSeq: number;
248
+ setup: SetupView;
249
+ }
250
+ /** Bytes for exactly one retained preview identity. */
251
+ export interface PreviewBytes extends PreviewIdentity {
252
+ data: Uint8Array<ArrayBuffer>;
253
+ }
254
+ /** One rendered-text → source candidate (`typst/locateSource` and the panel's selection toolbar). */
255
+ export interface SourceMatch {
256
+ file: string;
257
+ line: number;
258
+ column: number;
259
+ endLine: number;
260
+ excerpt: string;
261
+ score: number;
262
+ }
263
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;GAIG;AACH,OAAO,QAAQ,kCAAkC,CAAC;IAChD,UAAU,qBAAqB;QAC7B,eAAe,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;SAAE,CAAC;QACnD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eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE;QACT,QAAQ,EAAE,OAAO,CAAC;QAClB,eAAe,EAAE,OAAO,CAAC;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF,SAAS,EAAE,aAAa,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,UAAU,CAAC;IACnB;;;;;OAKG;IACH,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,uDAAuD;AACvD,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;CAC/B;AAMD,qGAAqG;AACrG,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Wire identity shared by both halves: the view types the host serves and
3
+ * the browser half renders, plus the strict zod codecs both arms materialize
4
+ * (`wire-schemas.ts`). Values and type-only imports only — this module is on
5
+ * the client-graph allowlist (`scripts/client-graph-authority.mjs`).
6
+ * @module dsh-typst/contract
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The one rendering of a diagnostic as model-facing text. Both the host
3
+ * tools and the browser panel (its feedback drafts) import this module, so a
4
+ * compile error reads the same in `typst_check` and in an Agent request.
5
+ * Pure values only: safe for the browser bundle.
6
+ * @module dsh-typst/diagnostic-text
7
+ */
8
+ import type { DiagnosticLocationView, DiagnosticView } from "./contract.js";
9
+ /** A location as `file:line:column`, or the explicit absence marker. */
10
+ export declare function formatDiagnosticLocation(location: DiagnosticLocationView | null): string;
11
+ /** One diagnostic: severity/message, location, excerpt, hints and call trace. */
12
+ export declare function diagnosticText(diagnostic: DiagnosticView): string;
13
+ //# sourceMappingURL=diagnostic-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostic-text.d.ts","sourceRoot":"","sources":["../src/diagnostic-text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5E,wEAAwE;AACxE,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,sBAAsB,GAAG,IAAI,GACtC,MAAM,CAIR;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,UAAU,EAAE,cAAc,GAAG,MAAM,CAajE"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The one rendering of a diagnostic as model-facing text. Both the host
3
+ * tools and the browser panel (its feedback drafts) import this module, so a
4
+ * compile error reads the same in `typst_check` and in an Agent request.
5
+ * Pure values only: safe for the browser bundle.
6
+ * @module dsh-typst/diagnostic-text
7
+ */
8
+ /** A location as `file:line:column`, or the explicit absence marker. */
9
+ export function formatDiagnosticLocation(location) {
10
+ return location
11
+ ? `${location.file}:${location.line}:${location.column}`
12
+ : "(no location)";
13
+ }
14
+ /** One diagnostic: severity/message, location, excerpt, hints and call trace. */
15
+ export function diagnosticText(diagnostic) {
16
+ const lines = [
17
+ `${diagnostic.severity}: ${diagnostic.message}`,
18
+ ` at ${formatDiagnosticLocation(diagnostic.location)}`,
19
+ ];
20
+ if (diagnostic.excerpt !== undefined)
21
+ lines.push(` | ${diagnostic.excerpt.trim()}`);
22
+ for (const hint of diagnostic.hints)
23
+ lines.push(` hint: ${hint}`);
24
+ for (const point of diagnostic.trace)
25
+ lines.push(` from ${formatDiagnosticLocation(point.location)}: ${point.message}`);
26
+ return lines.join("\n");
27
+ }
28
+ //# sourceMappingURL=diagnostic-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostic-text.js","sourceRoot":"","sources":["../src/diagnostic-text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,wEAAwE;AACxE,MAAM,UAAU,wBAAwB,CACtC,QAAuC;IAEvC,OAAO,QAAQ;QACb,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,MAAM,EAAE;QACxD,CAAC,CAAC,eAAe,CAAC;AACtB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,UAA0B;IACvD,MAAM,KAAK,GAAa;QACtB,GAAG,UAAU,CAAC,QAAQ,KAAK,UAAU,CAAC,OAAO,EAAE;QAC/C,QAAQ,wBAAwB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;KACxD,CAAC;IACF,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS;QAClC,KAAK,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IACnE,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,KAAK;QAClC,KAAK,CAAC,IAAI,CACR,UAAU,wBAAwB,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CACvE,CAAC;IACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Stable error classes and codes for the Typst domain. Mirrors the
3
+ * dsh-zotero convention: `HarnessError` subclasses carry a machine-routable
4
+ * code on the host half; the remote layer re-arms them as `RemoteError`s
5
+ * keyed `<domain>/<reason>`, discriminated by code, never by instanceof.
6
+ * @module dsh-typst/errors
7
+ */
8
+ import { HarnessError } from "@deepseek-ai/dsh-llm";
9
+ /** Typst is not installed anywhere this computer's lookup covers. */
10
+ export declare const TYPST_MISSING = "TYPST_MISSING";
11
+ /** The installed Typst is older than the supported minimum. */
12
+ export declare const TYPST_TOO_OLD = "TYPST_TOO_OLD";
13
+ /** Typst exists but does not run (`--version` failed, broken install). */
14
+ export declare const TYPST_UNUSABLE = "TYPST_UNUSABLE";
15
+ /** No main `.typ` file is chosen and none could be picked automatically. */
16
+ export declare const TYPST_NO_MAIN = "TYPST_NO_MAIN";
17
+ /** The requested preview does not exist (nothing compiled successfully yet). */
18
+ export declare const TYPST_NO_PREVIEW = "TYPST_NO_PREVIEW";
19
+ /** A requested snapshot/page/highlight no longer exists. */
20
+ export declare const TYPST_NOT_FOUND = "TYPST_NOT_FOUND";
21
+ /** An argument the schemas cannot express violates a domain constraint. */
22
+ export declare const TYPST_INVALID_ARGUMENT = "TYPST_INVALID_ARGUMENT";
23
+ /** A path resolves outside the session workspace. */
24
+ export declare const TYPST_PATH_OUTSIDE_WORKSPACE = "TYPST_PATH_OUTSIDE_WORKSPACE";
25
+ /** The compile did not settle within the caller's budget. */
26
+ export declare const TYPST_TIMEOUT = "TYPST_TIMEOUT";
27
+ /** `typst watch` died or could not start. */
28
+ export declare const TYPST_WATCH_FAILED = "TYPST_WATCH_FAILED";
29
+ /** The requested quote/text was not found in the rendered preview. */
30
+ export declare const TYPST_QUOTE_NOT_FOUND = "TYPST_QUOTE_NOT_FOUND";
31
+ /** The Typst workbench service is not composed. */
32
+ export declare const TYPST_NOT_COMPOSED = "TYPST_NOT_COMPOSED";
33
+ /** The attachment store is missing; rendered images cannot be returned. */
34
+ export declare const TYPST_ATTACHMENT_UNAVAILABLE = "TYPST_ATTACHMENT_UNAVAILABLE";
35
+ /** The document did not compile, so the requested output was not produced. */
36
+ export declare const TYPST_COMPILE_FAILED = "TYPST_COMPILE_FAILED";
37
+ /** The session's sandbox policy forbids writing the target. */
38
+ export declare const TYPST_SANDBOX_READ_ONLY = "TYPST_SANDBOX_READ_ONLY";
39
+ /** A granted writable root cannot be enforced: missing, not a directory, or a symlink. */
40
+ export declare const TYPST_SANDBOX_INVALID_ROOT = "TYPST_SANDBOX_INVALID_ROOT";
41
+ /** A requested page is outside the document or the render budget. */
42
+ export declare const TYPST_PAGE_OUT_OF_RANGE = "TYPST_PAGE_OUT_OF_RANGE";
43
+ /** The main file changed while a one-shot compile was in flight. */
44
+ export declare const TYPST_MAIN_CHANGED = "TYPST_MAIN_CHANGED";
45
+ /** The filesystem mtime is ahead of the host clock; the document cannot settle. */
46
+ export declare const TYPST_CLOCK_SKEW = "TYPST_CLOCK_SKEW";
47
+ /** The highlight target arguments are not exactly one valid target. */
48
+ export declare const TYPST_INVALID_TARGET = "TYPST_INVALID_TARGET";
49
+ /** A compile did not settle, so the answer cannot represent the new main file. */
50
+ export declare const TYPST_SETTLE_FAILED = "TYPST_SETTLE_FAILED";
51
+ /** Something unexpected; the message carries the domain fact. */
52
+ export declare const TYPST_UNEXPECTED = "TYPST_UNEXPECTED";
53
+ /** The one message every "typst workbench is not composed" answer spells. */
54
+ export declare const TYPST_NOT_COMPOSED_MESSAGE = "The Typst workbench service is not composed.";
55
+ export declare const TYPST_ERROR_CODES: readonly ["TYPST_MISSING", "TYPST_TOO_OLD", "TYPST_UNUSABLE", "TYPST_NO_MAIN", "TYPST_NO_PREVIEW", "TYPST_NOT_FOUND", "TYPST_INVALID_ARGUMENT", "TYPST_PATH_OUTSIDE_WORKSPACE", "TYPST_TIMEOUT", "TYPST_WATCH_FAILED", "TYPST_QUOTE_NOT_FOUND", "TYPST_NOT_COMPOSED", "TYPST_ATTACHMENT_UNAVAILABLE", "TYPST_COMPILE_FAILED", "TYPST_SANDBOX_READ_ONLY", "TYPST_SANDBOX_INVALID_ROOT", "TYPST_PAGE_OUT_OF_RANGE", "TYPST_MAIN_CHANGED", "TYPST_CLOCK_SKEW", "TYPST_INVALID_TARGET", "TYPST_SETTLE_FAILED", "TYPST_UNEXPECTED"];
56
+ /** Every stable error code a `TypstError` may carry. */
57
+ export type TypstErrorCode = (typeof TYPST_ERROR_CODES)[number];
58
+ /**
59
+ * Domain failure with a stable machine-routable code and an actionable,
60
+ * model-facing message. The tool registry renders it as `Error: <message>`
61
+ * with `isError: true`.
62
+ */
63
+ export declare class TypstError extends HarnessError {
64
+ readonly code: TypstErrorCode;
65
+ constructor(message: string, code: TypstErrorCode, options?: ErrorOptions);
66
+ }
67
+ /**
68
+ * The wire code each stable domain failure crosses the Typert boundary as.
69
+ * Typert's protocol reserves one `<domain>/<reason>` code per failure and
70
+ * discriminates `RemoteFailure` by that code; the details still carry the
71
+ * stable domain code so a handler that needs the finer domain fact can read
72
+ * it without matching message text.
73
+ */
74
+ export declare const TYPST_REMOTE_CODES: {
75
+ readonly TYPST_MISSING: "typst/missing";
76
+ readonly TYPST_TOO_OLD: "typst/too-old";
77
+ readonly TYPST_UNUSABLE: "typst/unusable";
78
+ readonly TYPST_NO_MAIN: "typst/no-main";
79
+ readonly TYPST_NO_PREVIEW: "typst/no-preview";
80
+ readonly TYPST_NOT_FOUND: "typst/not-found";
81
+ readonly TYPST_INVALID_ARGUMENT: "typst/invalid-argument";
82
+ readonly TYPST_PATH_OUTSIDE_WORKSPACE: "typst/path-outside-workspace";
83
+ readonly TYPST_TIMEOUT: "typst/timeout";
84
+ readonly TYPST_WATCH_FAILED: "typst/watch-failed";
85
+ readonly TYPST_QUOTE_NOT_FOUND: "typst/quote-not-found";
86
+ readonly TYPST_NOT_COMPOSED: "typst/not-composed";
87
+ readonly TYPST_ATTACHMENT_UNAVAILABLE: "typst/attachment-unavailable";
88
+ readonly TYPST_COMPILE_FAILED: "typst/compile-failed";
89
+ readonly TYPST_SANDBOX_READ_ONLY: "typst/sandbox-read-only";
90
+ readonly TYPST_SANDBOX_INVALID_ROOT: "typst/sandbox-invalid-root";
91
+ readonly TYPST_PAGE_OUT_OF_RANGE: "typst/page-out-of-range";
92
+ readonly TYPST_MAIN_CHANGED: "typst/main-changed";
93
+ readonly TYPST_CLOCK_SKEW: "typst/clock-skew";
94
+ readonly TYPST_INVALID_TARGET: "typst/invalid-target";
95
+ readonly TYPST_SETTLE_FAILED: "typst/settle-failed";
96
+ readonly TYPST_UNEXPECTED: "typst/unexpected";
97
+ };
98
+ /** Every Typert Remote failure code this plugin may emit. */
99
+ export type TypstRemoteCode = (typeof TYPST_REMOTE_CODES)[TypstErrorCode];
100
+ /**
101
+ * Rethrow a domain failure across the Typert wire as its own
102
+ * `<domain>/<reason>` code, with the stable domain code in `details`.
103
+ * Consumers discriminate by `error.code`, never by instanceof (the client
104
+ * never sees these classes).
105
+ * @param error - the thrown value.
106
+ * @returns never; throws a `RemoteError` keyed `typst/<reason>`.
107
+ */
108
+ export declare function rethrowRemote(error: unknown): never;
109
+ /** Install guidance shown whenever Typst cannot be found. */
110
+ export declare const INSTALL_HINT: string;
111
+ /**
112
+ * Wrap a domain call so every failure crosses the wire as a `RemoteError`
113
+ * with a stable `typst/<reason>` code (client remote calls never reject with
114
+ * anything else; they resolve `{ ok: false }`).
115
+ * @param call - the domain call.
116
+ * @returns the call's value.
117
+ */
118
+ export declare function domainCall<T>(call: () => Promise<T>): Promise<T>;
119
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,qEAAqE;AACrE,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,+DAA+D;AAC/D,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,0EAA0E;AAC1E,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,4EAA4E;AAC5E,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,gFAAgF;AAChF,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,4DAA4D;AAC5D,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAC/D,qDAAqD;AACrD,eAAO,MAAM,4BAA4B,iCAAiC,CAAC;AAC3E,6DAA6D;AAC7D,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,sEAAsE;AACtE,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAC7D,mDAAmD;AACnD,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,2EAA2E;AAC3E,eAAO,MAAM,4BAA4B,iCAAiC,CAAC;AAC3E,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAC3D,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AACjE,0FAA0F;AAC1F,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AACvE,qEAAqE;AACrE,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AACjE,oEAAoE;AACpE,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,mFAAmF;AACnF,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAC3D,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AACzD,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,6EAA6E;AAC7E,eAAO,MAAM,0BAA0B,iDACS,CAAC;AAEjD,eAAO,MAAM,iBAAiB,ggBAuBpB,CAAC;AAEX,wDAAwD;AACxD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,SAAiB,IAAI,EAAE,cAAc,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY;CAI1E;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;CAuB+B,CAAC;AAE/D,6DAA6D;AAC7D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,cAAc,CAAC,CAAC;AAE1E;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAcnD;AAED,6DAA6D;AAC7D,eAAO,MAAM,YAAY,QAGwE,CAAC;AAElG;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAMtE"}
package/lib/errors.js ADDED
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Stable error classes and codes for the Typst domain. Mirrors the
3
+ * dsh-zotero convention: `HarnessError` subclasses carry a machine-routable
4
+ * code on the host half; the remote layer re-arms them as `RemoteError`s
5
+ * keyed `<domain>/<reason>`, discriminated by code, never by instanceof.
6
+ * @module dsh-typst/errors
7
+ */
8
+ import { HarnessError } from "@deepseek-ai/dsh-llm";
9
+ import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
10
+ /** Typst is not installed anywhere this computer's lookup covers. */
11
+ export const TYPST_MISSING = "TYPST_MISSING";
12
+ /** The installed Typst is older than the supported minimum. */
13
+ export const TYPST_TOO_OLD = "TYPST_TOO_OLD";
14
+ /** Typst exists but does not run (`--version` failed, broken install). */
15
+ export const TYPST_UNUSABLE = "TYPST_UNUSABLE";
16
+ /** No main `.typ` file is chosen and none could be picked automatically. */
17
+ export const TYPST_NO_MAIN = "TYPST_NO_MAIN";
18
+ /** The requested preview does not exist (nothing compiled successfully yet). */
19
+ export const TYPST_NO_PREVIEW = "TYPST_NO_PREVIEW";
20
+ /** A requested snapshot/page/highlight no longer exists. */
21
+ export const TYPST_NOT_FOUND = "TYPST_NOT_FOUND";
22
+ /** An argument the schemas cannot express violates a domain constraint. */
23
+ export const TYPST_INVALID_ARGUMENT = "TYPST_INVALID_ARGUMENT";
24
+ /** A path resolves outside the session workspace. */
25
+ export const TYPST_PATH_OUTSIDE_WORKSPACE = "TYPST_PATH_OUTSIDE_WORKSPACE";
26
+ /** The compile did not settle within the caller's budget. */
27
+ export const TYPST_TIMEOUT = "TYPST_TIMEOUT";
28
+ /** `typst watch` died or could not start. */
29
+ export const TYPST_WATCH_FAILED = "TYPST_WATCH_FAILED";
30
+ /** The requested quote/text was not found in the rendered preview. */
31
+ export const TYPST_QUOTE_NOT_FOUND = "TYPST_QUOTE_NOT_FOUND";
32
+ /** The Typst workbench service is not composed. */
33
+ export const TYPST_NOT_COMPOSED = "TYPST_NOT_COMPOSED";
34
+ /** The attachment store is missing; rendered images cannot be returned. */
35
+ export const TYPST_ATTACHMENT_UNAVAILABLE = "TYPST_ATTACHMENT_UNAVAILABLE";
36
+ /** The document did not compile, so the requested output was not produced. */
37
+ export const TYPST_COMPILE_FAILED = "TYPST_COMPILE_FAILED";
38
+ /** The session's sandbox policy forbids writing the target. */
39
+ export const TYPST_SANDBOX_READ_ONLY = "TYPST_SANDBOX_READ_ONLY";
40
+ /** A granted writable root cannot be enforced: missing, not a directory, or a symlink. */
41
+ export const TYPST_SANDBOX_INVALID_ROOT = "TYPST_SANDBOX_INVALID_ROOT";
42
+ /** A requested page is outside the document or the render budget. */
43
+ export const TYPST_PAGE_OUT_OF_RANGE = "TYPST_PAGE_OUT_OF_RANGE";
44
+ /** The main file changed while a one-shot compile was in flight. */
45
+ export const TYPST_MAIN_CHANGED = "TYPST_MAIN_CHANGED";
46
+ /** The filesystem mtime is ahead of the host clock; the document cannot settle. */
47
+ export const TYPST_CLOCK_SKEW = "TYPST_CLOCK_SKEW";
48
+ /** The highlight target arguments are not exactly one valid target. */
49
+ export const TYPST_INVALID_TARGET = "TYPST_INVALID_TARGET";
50
+ /** A compile did not settle, so the answer cannot represent the new main file. */
51
+ export const TYPST_SETTLE_FAILED = "TYPST_SETTLE_FAILED";
52
+ /** Something unexpected; the message carries the domain fact. */
53
+ export const TYPST_UNEXPECTED = "TYPST_UNEXPECTED";
54
+ /** The one message every "typst workbench is not composed" answer spells. */
55
+ export const TYPST_NOT_COMPOSED_MESSAGE = "The Typst workbench service is not composed.";
56
+ export const TYPST_ERROR_CODES = [
57
+ TYPST_MISSING,
58
+ TYPST_TOO_OLD,
59
+ TYPST_UNUSABLE,
60
+ TYPST_NO_MAIN,
61
+ TYPST_NO_PREVIEW,
62
+ TYPST_NOT_FOUND,
63
+ TYPST_INVALID_ARGUMENT,
64
+ TYPST_PATH_OUTSIDE_WORKSPACE,
65
+ TYPST_TIMEOUT,
66
+ TYPST_WATCH_FAILED,
67
+ TYPST_QUOTE_NOT_FOUND,
68
+ TYPST_NOT_COMPOSED,
69
+ TYPST_ATTACHMENT_UNAVAILABLE,
70
+ TYPST_COMPILE_FAILED,
71
+ TYPST_SANDBOX_READ_ONLY,
72
+ TYPST_SANDBOX_INVALID_ROOT,
73
+ TYPST_PAGE_OUT_OF_RANGE,
74
+ TYPST_MAIN_CHANGED,
75
+ TYPST_CLOCK_SKEW,
76
+ TYPST_INVALID_TARGET,
77
+ TYPST_SETTLE_FAILED,
78
+ TYPST_UNEXPECTED,
79
+ ];
80
+ /**
81
+ * Domain failure with a stable machine-routable code and an actionable,
82
+ * model-facing message. The tool registry renders it as `Error: <message>`
83
+ * with `isError: true`.
84
+ */
85
+ export class TypstError extends HarnessError {
86
+ constructor(message, code, options) {
87
+ super(message, code, options);
88
+ this.name = "TypstError";
89
+ }
90
+ }
91
+ /**
92
+ * The wire code each stable domain failure crosses the Typert boundary as.
93
+ * Typert's protocol reserves one `<domain>/<reason>` code per failure and
94
+ * discriminates `RemoteFailure` by that code; the details still carry the
95
+ * stable domain code so a handler that needs the finer domain fact can read
96
+ * it without matching message text.
97
+ */
98
+ export const TYPST_REMOTE_CODES = {
99
+ [TYPST_MISSING]: "typst/missing",
100
+ [TYPST_TOO_OLD]: "typst/too-old",
101
+ [TYPST_UNUSABLE]: "typst/unusable",
102
+ [TYPST_NO_MAIN]: "typst/no-main",
103
+ [TYPST_NO_PREVIEW]: "typst/no-preview",
104
+ [TYPST_NOT_FOUND]: "typst/not-found",
105
+ [TYPST_INVALID_ARGUMENT]: "typst/invalid-argument",
106
+ [TYPST_PATH_OUTSIDE_WORKSPACE]: "typst/path-outside-workspace",
107
+ [TYPST_TIMEOUT]: "typst/timeout",
108
+ [TYPST_WATCH_FAILED]: "typst/watch-failed",
109
+ [TYPST_QUOTE_NOT_FOUND]: "typst/quote-not-found",
110
+ [TYPST_NOT_COMPOSED]: "typst/not-composed",
111
+ [TYPST_ATTACHMENT_UNAVAILABLE]: "typst/attachment-unavailable",
112
+ [TYPST_COMPILE_FAILED]: "typst/compile-failed",
113
+ [TYPST_SANDBOX_READ_ONLY]: "typst/sandbox-read-only",
114
+ [TYPST_SANDBOX_INVALID_ROOT]: "typst/sandbox-invalid-root",
115
+ [TYPST_PAGE_OUT_OF_RANGE]: "typst/page-out-of-range",
116
+ [TYPST_MAIN_CHANGED]: "typst/main-changed",
117
+ [TYPST_CLOCK_SKEW]: "typst/clock-skew",
118
+ [TYPST_INVALID_TARGET]: "typst/invalid-target",
119
+ [TYPST_SETTLE_FAILED]: "typst/settle-failed",
120
+ [TYPST_UNEXPECTED]: "typst/unexpected",
121
+ };
122
+ /**
123
+ * Rethrow a domain failure across the Typert wire as its own
124
+ * `<domain>/<reason>` code, with the stable domain code in `details`.
125
+ * Consumers discriminate by `error.code`, never by instanceof (the client
126
+ * never sees these classes).
127
+ * @param error - the thrown value.
128
+ * @returns never; throws a `RemoteError` keyed `typst/<reason>`.
129
+ */
130
+ export function rethrowRemote(error) {
131
+ if (error instanceof TypstError) {
132
+ throw new RemoteError(TYPST_REMOTE_CODES[error.code], error.message, {
133
+ code: error.code,
134
+ });
135
+ }
136
+ if (error instanceof RemoteError)
137
+ throw error;
138
+ throw new RemoteError(TYPST_REMOTE_CODES[TYPST_UNEXPECTED], error instanceof Error ? error.message : String(error), {
139
+ code: TYPST_UNEXPECTED,
140
+ });
141
+ }
142
+ /** Install guidance shown whenever Typst cannot be found. */
143
+ export const INSTALL_HINT = "Install Typst (for example `brew install typst`, `winget install --id Typst.Typst`, " +
144
+ "`cargo install --locked typst-cli`, or a release from " +
145
+ 'https://github.com/typst/typst/releases), or set its path in the plugin setting "Typst path".';
146
+ /**
147
+ * Wrap a domain call so every failure crosses the wire as a `RemoteError`
148
+ * with a stable `typst/<reason>` code (client remote calls never reject with
149
+ * anything else; they resolve `{ ok: false }`).
150
+ * @param call - the domain call.
151
+ * @returns the call's value.
152
+ */
153
+ export async function domainCall(call) {
154
+ try {
155
+ return await call();
156
+ }
157
+ catch (error) {
158
+ rethrowRemote(error);
159
+ }
160
+ }
161
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE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