@artkit-ai/core 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.
- package/LICENSE +202 -0
- package/README.md +64 -2
- package/dist/adapter.d.ts +119 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +45 -0
- package/dist/adapter.js.map +1 -0
- package/dist/assets.d.ts +62 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +145 -0
- package/dist/assets.js.map +1 -0
- package/dist/diff.d.ts +23 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +136 -0
- package/dist/diff.js.map +1 -0
- package/dist/engine.d.ts +76 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +348 -0
- package/dist/engine.js.map +1 -0
- package/dist/envelope.d.ts +92 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +46 -0
- package/dist/envelope.js.map +1 -0
- package/dist/errors.d.ts +45 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +145 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +42 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +25 -0
- package/dist/events.js.map +1 -0
- package/dist/fonts/index.d.ts +10 -0
- package/dist/fonts/index.d.ts.map +1 -0
- package/dist/fonts/index.js +20 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/sora-data.d.ts +4 -0
- package/dist/fonts/sora-data.d.ts.map +1 -0
- package/dist/fonts/sora-data.js +7 -0
- package/dist/fonts/sora-data.js.map +1 -0
- package/dist/i18n.d.ts +103 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +112 -0
- package/dist/i18n.js.map +1 -0
- package/dist/ids.d.ts +26 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +81 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/jsonschema.d.ts +14 -0
- package/dist/jsonschema.d.ts.map +1 -0
- package/dist/jsonschema.js +91 -0
- package/dist/jsonschema.js.map +1 -0
- package/dist/logger.d.ts +28 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +20 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory.d.ts +15 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +173 -0
- package/dist/memory.js.map +1 -0
- package/dist/migrations.d.ts +13 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +37 -0
- package/dist/migrations.js.map +1 -0
- package/dist/projection.d.ts +56 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +115 -0
- package/dist/projection.js.map +1 -0
- package/dist/registry.d.ts +62 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +89 -0
- package/dist/registry.js.map +1 -0
- package/dist/runtime-globals.d.ts +47 -0
- package/dist/runtime-globals.d.ts.map +1 -0
- package/dist/runtime-globals.js +4 -0
- package/dist/runtime-globals.js.map +1 -0
- package/dist/sanitize.d.ts +17 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +67 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/service.d.ts +107 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +367 -0
- package/dist/service.js.map +1 -0
- package/dist/store.d.ts +73 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +2 -0
- package/dist/store.js.map +1 -0
- package/dist/testing/index.d.ts +31 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +178 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/theme.d.ts +110 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +194 -0
- package/dist/theme.js.map +1 -0
- package/dist/ui.d.ts +71 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +72 -0
- package/dist/ui.js.map +1 -0
- package/dist/zip.d.ts +13 -0
- package/dist/zip.d.ts.map +1 -0
- package/dist/zip.js +78 -0
- package/dist/zip.js.map +1 -0
- package/fonts/OFL-Sora.txt +93 -0
- package/package.json +55 -3
- package/src/adapter.ts +180 -0
- package/src/assets.ts +199 -0
- package/src/diff.ts +169 -0
- package/src/engine.ts +434 -0
- package/src/envelope.ts +75 -0
- package/src/errors.ts +183 -0
- package/src/events.ts +57 -0
- package/src/fonts/index.ts +21 -0
- package/src/fonts/sora-data.ts +10 -0
- package/src/i18n.ts +130 -0
- package/src/ids.ts +96 -0
- package/src/index.ts +34 -0
- package/src/jsonschema.ts +83 -0
- package/src/logger.ts +44 -0
- package/src/memory.ts +224 -0
- package/src/migrations.ts +58 -0
- package/src/projection.ts +158 -0
- package/src/registry.ts +156 -0
- package/src/runtime-globals.ts +57 -0
- package/src/sanitize.ts +67 -0
- package/src/service.ts +507 -0
- package/src/store.ts +79 -0
- package/src/testing/index.ts +237 -0
- package/src/theme.ts +229 -0
- package/src/ui.ts +130 -0
- package/src/zip.ts +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @artkit-ai/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The runtime-neutral heart of artkit: artifact envelope, kind contract and registry, the atomic operation engine, versioning with automatic rebase, migrations, diff, lint and projection helpers, the error catalog, store/asset/event contracts and the high-level artifact service.
|
|
4
|
+
|
|
5
|
+
Its only dependency is `zod`. It runs in browsers, Node 22+, edge runtimes and workers (no DOM, no Node APIs).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @artkit-ai/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createArtifactService, createMemoryStore, createRegistry } from '@artkit-ai/core';
|
|
15
|
+
import { documentKind } from '@artkit-ai/kind-document';
|
|
16
|
+
|
|
17
|
+
const registry = createRegistry({ kinds: [documentKind] });
|
|
18
|
+
const service = createArtifactService({
|
|
19
|
+
registry,
|
|
20
|
+
store: createMemoryStore(),
|
|
21
|
+
authorize: (action, artifact, scope) => scope.workspaceId === 'acme',
|
|
22
|
+
locale: 'pt-BR',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const scope = { workspaceId: 'acme', actor: { type: 'agent', id: 'agent-proposals' } } as const;
|
|
26
|
+
const { artifact } = await service.create(scope, {
|
|
27
|
+
kind: 'document',
|
|
28
|
+
title: 'Proposta técnica',
|
|
29
|
+
input: { format: 'markdown', source: '# Proposta\n\n## Escopo\n\nPortal de fornecedores.' },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const result = await service.apply(scope, {
|
|
33
|
+
artifactId: artifact.id,
|
|
34
|
+
baseVersion: artifact.version,
|
|
35
|
+
operations: [{ op: 'set_title', title: 'Proposta técnica v2' }],
|
|
36
|
+
});
|
|
37
|
+
console.log(result.version, result.diff, result.lint);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## What is inside
|
|
41
|
+
|
|
42
|
+
| Area | API |
|
|
43
|
+
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| Envelope | `Artifact`, `envelopeSchema`, statuses and lifecycle transitions |
|
|
45
|
+
| Kinds | `ArtifactKind`, `defineKind`, `createRegistry` (kinds, themes, exporters, limits) |
|
|
46
|
+
| Engine | `applyOperations` (validate → clone → apply → derive → revalidate → limits → diff → lint, all or nothing), `prepareContent`, envelope operations `set_title`, `set_theme`, `set_locale`, `replace_content` |
|
|
47
|
+
| Service | `createArtifactService`: authorization hook, `baseVersion` with automatic rebase or `VERSION_CONFLICT`, idempotency keys, locks, approval policy, history and restore, export orchestration with timeout |
|
|
48
|
+
| Projection | `projectItems`, `paginate` (token budget and cursor), `selectRange`, `delimitProjection` |
|
|
49
|
+
| Diff | `diffCollection` (added, removed, changed, moved), `diffFields` |
|
|
50
|
+
| Errors | `ArtifactError`, `toModelError` (never leaks stack traces), pt-BR and English catalogs |
|
|
51
|
+
| Security | `sanitizeDeep` (control characters, NFC), `linkSchema`, `checkAsset` (magic-byte MIME sniffing, size, domains), `sanitizeSvg` |
|
|
52
|
+
| Schemas | `toJsonSchema` with `default`, `strict` and `compact` profiles; `stripNulls` |
|
|
53
|
+
| Stores | `ArtifactStore`, `AssetStore` contracts; `createMemoryStore`, `createMemoryAssetStore` (reference adapters) |
|
|
54
|
+
| UI contracts | `RenderContext`, `EditorBindings`, `themeCssVariables` (shared by renderers, editors and `@artkit-ai/react`) |
|
|
55
|
+
| Events & logs | `createEventBus`, `Logger` (metadata only), metric hooks |
|
|
56
|
+
|
|
57
|
+
`@artkit-ai/core/testing` exports `defineStoreContractTests` (every store adapter must pass it) and `defineKindConformanceTests` (every kind, native or third-party).
|
|
58
|
+
|
|
59
|
+
## Notes
|
|
60
|
+
|
|
61
|
+
- `apply` is pure and deterministic: no clock, network or randomness. Replays always produce the same content.
|
|
62
|
+
- The memory store lives here (not in `@artkit-ai/node`) so it also works in the browser playground and in edge runtimes; `@artkit-ai/node` re-exports it.
|
|
63
|
+
- `INTERNAL_ERROR` extends the spec's error catalog for unexpected failures, so details never reach the model.
|
|
64
|
+
|
|
65
|
+
License: Apache-2.0.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { ErrorIssue } from './errors.js';
|
|
3
|
+
import type { Theme } from './theme.js';
|
|
4
|
+
/** Contract every native format implements (spec §8). Adapters own all knowledge about their format. */
|
|
5
|
+
export interface FormatAdapter<Content = unknown, Operation = unknown> {
|
|
6
|
+
/** Format name stored in the envelope: `markdown`, `univer-sheet`, `openui`. */
|
|
7
|
+
format: string;
|
|
8
|
+
/** Version of the native format or third-party library the content is written with (e.g. `univer-sheet@0.x`). */
|
|
9
|
+
formatVersion: string;
|
|
10
|
+
/** Format versions this adapter can read; `formatVersion` is the one it writes. */
|
|
11
|
+
readableVersions: string[];
|
|
12
|
+
label: string;
|
|
13
|
+
/** Smallest valid content, used when an artifact is created from operations only. */
|
|
14
|
+
empty(): Content;
|
|
15
|
+
/** Validates content (already parsed from the store or from the model). Throws nothing; reports issues. */
|
|
16
|
+
validate(content: unknown, ctx: AdapterContext): ValidationResult<Content>;
|
|
17
|
+
operationSchema: z.ZodType<Operation>;
|
|
18
|
+
/**
|
|
19
|
+
* Applies a run of content operations on a draft. The draft is a private copy; mutations are kept only when the
|
|
20
|
+
* whole batch succeeds. Must not read the clock, the network or randomness.
|
|
21
|
+
*/
|
|
22
|
+
apply(content: Content, operations: Operation[], ctx: AdapterContext): Promise<ApplyResult<Content>>;
|
|
23
|
+
/** Compact reading for the model (outline, section, range, full), with budget and cursor. */
|
|
24
|
+
read(content: Content, request: ReadRequest): ReadResult;
|
|
25
|
+
diff(before: Content, after: Content, locale?: string): ChangeSummary[];
|
|
26
|
+
lint(content: Content, ctx: LintContext): LintIssue[];
|
|
27
|
+
/** Best-effort preview while the model streams; drops incomplete trailing items. Returns undefined when unusable. */
|
|
28
|
+
parsePartial(raw: string): Content | undefined;
|
|
29
|
+
migrations: FormatMigration[];
|
|
30
|
+
/** Counters checked against `limits` (same keys as `measure`). */
|
|
31
|
+
limits: FormatLimits;
|
|
32
|
+
measure?(content: Content): Record<string, number>;
|
|
33
|
+
instructions: FormatInstructions;
|
|
34
|
+
}
|
|
35
|
+
export interface AdapterContext {
|
|
36
|
+
locale: string;
|
|
37
|
+
theme: Theme;
|
|
38
|
+
/** Fails the batch with `OPERATION_FAILED`; the message and hint are written for the model to fix the call. */
|
|
39
|
+
fail(message: string, options?: {
|
|
40
|
+
hint?: string;
|
|
41
|
+
path?: string;
|
|
42
|
+
}): never;
|
|
43
|
+
}
|
|
44
|
+
export type ValidationResult<Content> = {
|
|
45
|
+
ok: true;
|
|
46
|
+
content: Content;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
issues: ErrorIssue[];
|
|
50
|
+
};
|
|
51
|
+
export interface ApplyResult<Content> {
|
|
52
|
+
content: Content;
|
|
53
|
+
/** Anchors, declarations, ranges or sheets created by the batch (e.g. `escopo`, `kpi1`, `Resumo!A1:D3`). */
|
|
54
|
+
createdRefs: string[];
|
|
55
|
+
warnings: LintIssue[];
|
|
56
|
+
}
|
|
57
|
+
export type ReadMode = 'outline' | 'section' | 'statements' | 'range' | 'full';
|
|
58
|
+
export interface ReadRequest {
|
|
59
|
+
mode: ReadMode;
|
|
60
|
+
/** Format-specific selection: anchors, A1 range, declaration names. */
|
|
61
|
+
range?: string;
|
|
62
|
+
/** Token budget; text is cut at an item boundary and a cursor is returned. */
|
|
63
|
+
maxTokens?: number;
|
|
64
|
+
cursor?: string;
|
|
65
|
+
locale: string;
|
|
66
|
+
charsPerToken?: number;
|
|
67
|
+
}
|
|
68
|
+
export interface ReadResult {
|
|
69
|
+
text: string;
|
|
70
|
+
truncated: boolean;
|
|
71
|
+
/** Present when truncated: pass it back to continue reading. */
|
|
72
|
+
cursor?: string;
|
|
73
|
+
}
|
|
74
|
+
export type LintSeverity = 'warning' | 'info';
|
|
75
|
+
export interface LintIssue {
|
|
76
|
+
code: string;
|
|
77
|
+
severity: LintSeverity;
|
|
78
|
+
/** `section:cronograma`, `cell:Resumo!D14`, `slide:cronograma`, `node:api`… */
|
|
79
|
+
target: string;
|
|
80
|
+
message: string;
|
|
81
|
+
hint?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface LintContext {
|
|
84
|
+
locale: string;
|
|
85
|
+
theme: Theme;
|
|
86
|
+
}
|
|
87
|
+
export type ChangeType = 'added' | 'removed' | 'changed' | 'moved';
|
|
88
|
+
export interface ChangeSummary {
|
|
89
|
+
type: ChangeType;
|
|
90
|
+
/** Same vocabulary as lint targets; the core compares these to detect rebase conflicts. */
|
|
91
|
+
target: string;
|
|
92
|
+
summary: string;
|
|
93
|
+
}
|
|
94
|
+
export interface FormatMigration {
|
|
95
|
+
from: string;
|
|
96
|
+
to: string;
|
|
97
|
+
migrate(content: unknown): unknown;
|
|
98
|
+
}
|
|
99
|
+
export type FormatLimits = Record<string, number>;
|
|
100
|
+
export interface FormatExample {
|
|
101
|
+
title: string;
|
|
102
|
+
operations?: unknown[];
|
|
103
|
+
content?: unknown;
|
|
104
|
+
}
|
|
105
|
+
export interface FormatInstructions {
|
|
106
|
+
/** What the format is and when to use it. */
|
|
107
|
+
summary: string;
|
|
108
|
+
/** Short, verifiable rules. */
|
|
109
|
+
rules: string[];
|
|
110
|
+
examples: FormatExample[];
|
|
111
|
+
}
|
|
112
|
+
export type AnyFormatAdapter = FormatAdapter<any, any>;
|
|
113
|
+
export declare class FormatDefinitionError extends Error {
|
|
114
|
+
constructor(format: string, problem: string);
|
|
115
|
+
}
|
|
116
|
+
/** Checks an adapter's shape. The registry runs it on `register`; third-party adapters can call it directly. */
|
|
117
|
+
export declare function defineFormat<Content, Operation>(adapter: FormatAdapter<Content, Operation>): FormatAdapter<Content, Operation>;
|
|
118
|
+
export declare function assertFormatContract(adapter: AnyFormatAdapter): void;
|
|
119
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,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Aa,CAAC,OAAO,EAAE,SAAS,CAAC,GACzC,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,CAGnC;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAoCpE"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class FormatDefinitionError extends Error {
|
|
2
|
+
constructor(format, problem) {
|
|
3
|
+
super(`Invalid format "${format}": ${problem}`);
|
|
4
|
+
this.name = 'FormatDefinitionError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
const FORMAT_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
8
|
+
const VERSION_NAME = /^[a-z0-9][a-z0-9.+@-]{0,63}$/i;
|
|
9
|
+
/** Checks an adapter's shape. The registry runs it on `register`; third-party adapters can call it directly. */
|
|
10
|
+
export function defineFormat(adapter) {
|
|
11
|
+
assertFormatContract(adapter);
|
|
12
|
+
return adapter;
|
|
13
|
+
}
|
|
14
|
+
export function assertFormatContract(adapter) {
|
|
15
|
+
const name = typeof adapter?.format === 'string' ? adapter.format : '<unnamed>';
|
|
16
|
+
if (!FORMAT_NAME.test(name))
|
|
17
|
+
throw new FormatDefinitionError(name, 'format must match /^[a-z][a-z0-9-]{0,63}$/');
|
|
18
|
+
if (typeof adapter.formatVersion !== 'string' || !VERSION_NAME.test(adapter.formatVersion)) {
|
|
19
|
+
throw new FormatDefinitionError(name, 'formatVersion must be a non-empty version string');
|
|
20
|
+
}
|
|
21
|
+
if (!Array.isArray(adapter.readableVersions) || !adapter.readableVersions.includes(adapter.formatVersion)) {
|
|
22
|
+
throw new FormatDefinitionError(name, 'readableVersions must include formatVersion');
|
|
23
|
+
}
|
|
24
|
+
if (!(adapter.operationSchema && typeof adapter.operationSchema.safeParse === 'function')) {
|
|
25
|
+
throw new FormatDefinitionError(name, 'operationSchema must be a zod schema');
|
|
26
|
+
}
|
|
27
|
+
for (const fn of ['empty', 'validate', 'apply', 'read', 'diff', 'lint', 'parsePartial']) {
|
|
28
|
+
if (typeof adapter[fn] !== 'function')
|
|
29
|
+
throw new FormatDefinitionError(name, `${fn} must be a function`);
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(adapter.migrations))
|
|
32
|
+
throw new FormatDefinitionError(name, 'migrations must be an array');
|
|
33
|
+
for (const migration of adapter.migrations) {
|
|
34
|
+
if (!adapter.readableVersions.includes(migration.from) ||
|
|
35
|
+
!adapter.readableVersions.includes(migration.to)) {
|
|
36
|
+
throw new FormatDefinitionError(name, `migration ${migration.from}→${migration.to} must use readable versions`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!adapter.instructions ||
|
|
40
|
+
typeof adapter.instructions.summary !== 'string' ||
|
|
41
|
+
!Array.isArray(adapter.instructions.rules)) {
|
|
42
|
+
throw new FormatDefinitionError(name, 'instructions need summary, rules and examples');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AA6HA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,MAAc,EAAE,OAAe;QACzC,KAAK,CAAC,mBAAmB,MAAM,MAAM,OAAO,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAC7C,MAAM,YAAY,GAAG,+BAA+B,CAAC;AAErD,gHAAgH;AAChH,MAAM,UAAU,YAAY,CAC1B,OAA0C;IAE1C,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,MAAM,IAAI,GAAG,OAAO,OAAO,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,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I,OAAO,CAAC,UAAU,EAAE,CAAC;QAC3C,IACE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC;YAClD,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,EAChD,CAAC;YACD,MAAM,IAAI,qBAAqB,CAC7B,IAAI,EACJ,aAAa,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,EAAE,6BAA6B,CACzE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,IACE,CAAC,OAAO,CAAC,YAAY;QACrB,OAAO,OAAO,CAAC,YAAY,CAAC,OAAO,KAAK,QAAQ;QAChD,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAC1C,CAAC;QACD,MAAM,IAAI,qBAAqB,CAAC,IAAI,EAAE,+CAA+C,CAAC,CAAC;IACzF,CAAC;AACH,CAAC"}
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ASSET_REF_PATTERN: RegExp;
|
|
3
|
+
export declare const assetRefSchema: z.ZodString;
|
|
4
|
+
export type AssetRef = string;
|
|
5
|
+
export declare function assetIdFromRef(ref: AssetRef): string;
|
|
6
|
+
export interface AssetMeta {
|
|
7
|
+
mimeType: string;
|
|
8
|
+
filename?: string;
|
|
9
|
+
/** External URL the bytes came from, checked against the allowed domains. */
|
|
10
|
+
sourceUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* `upload` (default): bytes from users or models, validated by magic bytes and the MIME allowlist.
|
|
13
|
+
* `generated`: files produced by artkit's own exporters (docx, xlsx, pptx…); only the size limit applies,
|
|
14
|
+
* since their type is known and they are never rendered inline from the asset store.
|
|
15
|
+
*/
|
|
16
|
+
origin?: 'upload' | 'generated';
|
|
17
|
+
}
|
|
18
|
+
export interface StoredAssetInfo {
|
|
19
|
+
ref: AssetRef;
|
|
20
|
+
mimeType: string;
|
|
21
|
+
size: number;
|
|
22
|
+
/** SHA-256 hex of the stored bytes. */
|
|
23
|
+
hash: string;
|
|
24
|
+
filename?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ResolvedAsset {
|
|
27
|
+
bytes: Uint8Array;
|
|
28
|
+
mimeType: string;
|
|
29
|
+
}
|
|
30
|
+
/** What exporters and renderers use to read assets; implemented on top of an AssetStore. */
|
|
31
|
+
export interface AssetResolver {
|
|
32
|
+
resolve(ref: AssetRef): Promise<ResolvedAsset>;
|
|
33
|
+
}
|
|
34
|
+
export declare const DEFAULT_ALLOWED_MIME_TYPES: readonly ['image/png', 'image/jpeg', 'image/webp', 'image/gif', 'image/svg+xml'];
|
|
35
|
+
export interface AssetPolicy {
|
|
36
|
+
allowedMimeTypes: readonly string[];
|
|
37
|
+
maxBytes: number;
|
|
38
|
+
/** Size limit for files generated by exporters (`origin: 'generated'`); defaults to `maxBytes`. */
|
|
39
|
+
maxGeneratedBytes?: number;
|
|
40
|
+
/** Domains accepted for external URLs. Empty means external URLs are refused (spec §6.5). */
|
|
41
|
+
allowedDomains: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
export declare const defaultAssetPolicy: AssetPolicy;
|
|
44
|
+
/** Detects the real MIME type from magic bytes; never trusts the declared one alone. */
|
|
45
|
+
export declare function sniffMimeType(bytes: Uint8Array): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Sanitizes SVG bytes: removes scripts, foreign objects, entities, event handlers, javascript: URLs and
|
|
48
|
+
* external references. Returns undefined when the result does not look like an SVG.
|
|
49
|
+
*/
|
|
50
|
+
export declare function sanitizeSvg(svg: string): string | undefined;
|
|
51
|
+
export interface CheckedAsset {
|
|
52
|
+
bytes: Uint8Array;
|
|
53
|
+
mimeType: string;
|
|
54
|
+
}
|
|
55
|
+
/** Validates bytes and metadata against the policy. Throws `ASSET_REJECTED` with the reason. */
|
|
56
|
+
export declare function checkAsset(bytes: Uint8Array, meta: AssetMeta, policy?: AssetPolicy, locale?: string): CheckedAsset;
|
|
57
|
+
export declare function isAllowedUrl(url: string, allowedDomains: readonly string[]): boolean;
|
|
58
|
+
/** SHA-256 hex digest using Web Crypto (available in browsers, Node 22, edge and workers). */
|
|
59
|
+
export declare function sha256Hex(bytes: Uint8Array): Promise<string>;
|
|
60
|
+
/** Encodes bytes as a data URL (used by headless render, which blocks the network). */
|
|
61
|
+
export declare function toDataUrl(bytes: Uint8Array, mimeType: string): string;
|
|
62
|
+
//# sourceMappingURL=assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,iBAAiB,QAAiD,CAAC;AAEhF,eAAO,MAAM,cAAc,aAG0D,CAAC;AAEtF,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAEpD;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,QAAQ,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,4FAA4F;AAC5F,MAAM,WAAW,aAAa;IAC5B,OAAO,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