@artkit-ai/react 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.
- package/LICENSE +202 -0
- package/README.md +145 -2
- package/dist/cache.d.ts +35 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +116 -0
- package/dist/cache.js.map +1 -0
- package/dist/client.d.ts +79 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +260 -0
- package/dist/client.js.map +1 -0
- package/dist/components/approval.d.ts +34 -0
- package/dist/components/approval.d.ts.map +1 -0
- package/dist/components/approval.js +80 -0
- package/dist/components/approval.js.map +1 -0
- package/dist/components/card.d.ts +22 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +16 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/editor.d.ts +28 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +161 -0
- package/dist/components/editor.js.map +1 -0
- package/dist/components/icons.d.ts +8 -0
- package/dist/components/icons.d.ts.map +1 -0
- package/dist/components/icons.js +14 -0
- package/dist/components/icons.js.map +1 -0
- package/dist/components/panel.d.ts +34 -0
- package/dist/components/panel.d.ts.map +1 -0
- package/dist/components/panel.js +216 -0
- package/dist/components/panel.js.map +1 -0
- package/dist/components/shared.d.ts +71 -0
- package/dist/components/shared.d.ts.map +1 -0
- package/dist/components/shared.js +104 -0
- package/dist/components/shared.js.map +1 -0
- package/dist/components/version-diff.d.ts +35 -0
- package/dist/components/version-diff.d.ts.map +1 -0
- package/dist/components/version-diff.js +85 -0
- package/dist/components/version-diff.js.map +1 -0
- package/dist/components/view.d.ts +40 -0
- package/dist/components/view.d.ts.map +1 -0
- package/dist/components/view.js +75 -0
- package/dist/components/view.js.map +1 -0
- package/dist/context.d.ts +59 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +13 -0
- package/dist/context.js.map +1 -0
- package/dist/controls.d.ts +145 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +188 -0
- package/dist/controls.js.map +1 -0
- package/dist/download.d.ts +4 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +20 -0
- package/dist/download.js.map +1 -0
- package/dist/editor-session.d.ts +184 -0
- package/dist/editor-session.d.ts.map +1 -0
- package/dist/editor-session.js +614 -0
- package/dist/editor-session.js.map +1 -0
- package/dist/hooks.d.ts +85 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +297 -0
- package/dist/hooks.js.map +1 -0
- package/dist/i18n.d.ts +197 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +207 -0
- package/dist/i18n.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/kit-css.d.ts +3 -0
- package/dist/kit-css.d.ts.map +1 -0
- package/dist/kit-css.js +5 -0
- package/dist/kit-css.js.map +1 -0
- package/dist/line-diff.d.ts +25 -0
- package/dist/line-diff.d.ts.map +1 -0
- package/dist/line-diff.js +96 -0
- package/dist/line-diff.js.map +1 -0
- package/dist/partial-json.d.ts +8 -0
- package/dist/partial-json.d.ts.map +1 -0
- package/dist/partial-json.js +176 -0
- package/dist/partial-json.js.map +1 -0
- package/dist/provider.d.ts +42 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +95 -0
- package/dist/provider.js.map +1 -0
- package/dist/styles.d.ts +25 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +203 -0
- package/dist/styles.js.map +1 -0
- package/dist/toolbar.d.ts +90 -0
- package/dist/toolbar.d.ts.map +1 -0
- package/dist/toolbar.js +233 -0
- package/dist/toolbar.js.map +1 -0
- package/package.json +50 -3
- package/src/cache.ts +132 -0
- package/src/client.ts +390 -0
- package/src/components/approval.tsx +219 -0
- package/src/components/card.tsx +87 -0
- package/src/components/editor.tsx +392 -0
- package/src/components/icons.tsx +14 -0
- package/src/components/panel.tsx +591 -0
- package/src/components/shared.tsx +207 -0
- package/src/components/version-diff.tsx +266 -0
- package/src/components/view.tsx +199 -0
- package/src/context.ts +82 -0
- package/src/controls.tsx +587 -0
- package/src/download.ts +23 -0
- package/src/editor-session.ts +738 -0
- package/src/hooks.ts +411 -0
- package/src/i18n.ts +217 -0
- package/src/index.ts +160 -0
- package/src/kit-css.ts +5 -0
- package/src/line-diff.ts +111 -0
- package/src/partial-json.ts +160 -0
- package/src/provider.tsx +176 -0
- package/src/styles.ts +222 -0
- package/src/toolbar.tsx +536 -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,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @artkit-ai/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React layer for [artkit](../../docs/spec.md) artifacts (spec §13): provider, read-only views, kind editor host, assistant-style panel, chat card, approval screen, version diff, hooks and streaming preview.
|
|
4
|
+
|
|
5
|
+
The React layer never touches a store. It talks to an `ArtifactClient`: HTTP against the `@artkit-ai/node` routes, or an in-process `ArtifactService` for playgrounds, tests and local apps.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @artkit-ai/react @artkit-ai/core react react-dom
|
|
11
|
+
# plus the kinds you show, e.g.
|
|
12
|
+
pnpm add @artkit-ai/kind-document
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires React 19.
|
|
16
|
+
|
|
17
|
+
## Provider
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { createRegistry } from '@artkit-ai/core';
|
|
21
|
+
import { documentKind } from '@artkit-ai/kind-document';
|
|
22
|
+
import { ArtifactProvider, createHttpClient } from '@artkit-ai/react';
|
|
23
|
+
|
|
24
|
+
const registry = createRegistry({ kinds: [documentKind] });
|
|
25
|
+
const client = createHttpClient({
|
|
26
|
+
baseUrl: '/api/artifacts',
|
|
27
|
+
headers: () => ({ Authorization: `Bearer ${token()}` }),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const loaders = {
|
|
31
|
+
// Renderers load the first time a kind is shown.
|
|
32
|
+
renderers: {
|
|
33
|
+
document: () =>
|
|
34
|
+
import('@artkit-ai/kind-document/react').then((m) => ({
|
|
35
|
+
Renderer: m.DocumentRenderer,
|
|
36
|
+
css: m.documentCss,
|
|
37
|
+
})),
|
|
38
|
+
},
|
|
39
|
+
// Editors load only when the user enters edit mode (spec §13.6).
|
|
40
|
+
editors: {
|
|
41
|
+
document: () => import('@artkit-ai/kind-document/edit').then((m) => ({ Editor: m.DocumentEditor })),
|
|
42
|
+
},
|
|
43
|
+
// Exporters with runtime 'any' | 'browser' run in the browser; other formats go through the server.
|
|
44
|
+
exporters: {
|
|
45
|
+
document: () => import('@artkit-ai/kind-document/export').then((m) => m.documentExporters),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export function App() {
|
|
50
|
+
return (
|
|
51
|
+
<ArtifactProvider
|
|
52
|
+
registry={registry}
|
|
53
|
+
client={client}
|
|
54
|
+
loaders={loaders}
|
|
55
|
+
locale="pt-BR"
|
|
56
|
+
exportFormats={{ document: ['pdf'] }}
|
|
57
|
+
>
|
|
58
|
+
{/* … */}
|
|
59
|
+
</ArtifactProvider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
| Prop | Purpose |
|
|
65
|
+
| ------------------------------- | ----------------------------------------------------------------------------------- |
|
|
66
|
+
| `registry` | Core registry; kinds provide `parsePartial`, `apply`, `project`, `diff`, `lint`. |
|
|
67
|
+
| `client` | `createHttpClient(...)` or `createServiceClient(service, scope)`. |
|
|
68
|
+
| `loaders` | Lazy `renderers`, `editors`, `exporters` per kind. Read once per kind. |
|
|
69
|
+
| `locale` | UI locale (`pt-BR` and `en` built in). Artifacts keep their own locale for content. |
|
|
70
|
+
| `messages` | Extra or overriding UI strings per locale (`{ es: { tabHistory: 'Historial' } }`). |
|
|
71
|
+
| `theme`, `themes`, `darkThemes` | Application theme, extra artifact themes, explicit dark variants. |
|
|
72
|
+
| `colorScheme` | `system` (default, follows `prefers-color-scheme`), `light` or `dark`. |
|
|
73
|
+
| `resolveAssetUrl`, `assets` | Asset lookup for renderers and for browser exports. |
|
|
74
|
+
| `exportFormats` | Formats the server can export, per kind (shown in the export menu). |
|
|
75
|
+
| `injectStyles`, `nonce` | Disable CSS injection, or pass a CSP nonce. |
|
|
76
|
+
|
|
77
|
+
Without a renderer loader a kind is shown as formatted JSON; without an editor loader `ArtifactEditor` falls back to `ArtifactView`.
|
|
78
|
+
|
|
79
|
+
## Components
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
<ArtifactCard artifact={summary} onOpen={(a) => setOpen(a.id)} streaming={isStreaming} />
|
|
83
|
+
<ArtifactPanel id={openId} permission="edit" onClose={() => setOpen(undefined)} />
|
|
84
|
+
<ArtifactView artifact={artifact} />
|
|
85
|
+
<ArtifactView kind="document" partial={streamedJsonOrObject} />
|
|
86
|
+
<ArtifactEditor id={id} groupingWindowMs={600} onCommitted={(r) => console.log(r.version)} />
|
|
87
|
+
<ArtifactApproval id={id} onApproved={…} onRejected={(a, reason) => …} />
|
|
88
|
+
<ArtifactVersionDiff id={id} from={3} to={5} defaultLayout="split" />
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- **`ArtifactView`**: read-only by kind. Takes `artifact`, or `id` (+ `version`). `partial` accepts a partial object or the raw JSON text streamed so far (parsed with `parsePartialJson`, then `kind.parsePartial`); it renders with a "provisional" badge and is replaced as soon as a newer committed version arrives (spec §13.4).
|
|
92
|
+
- **`ArtifactEditor`**: hosts the kind editor (see below). `permission="read"`, a missing editor loader or `lockedBy` (another actor holds the lock; `partial` then shows the streaming preview) render the view instead.
|
|
93
|
+
- **`ArtifactPanel`**: View / Code (formatted JSON, read-only) / History tabs, version selector, export menu, status badge and lifecycle actions (submit, approve, reject with reason, publish, archive). Tabs and menus follow the WAI-ARIA keyboard patterns.
|
|
94
|
+
- **`ArtifactCard`**: compact card for chat messages: title, kind, version, status, open action (button or `href`).
|
|
95
|
+
- **`ArtifactApproval`**: diff of the pending version against `meta.publishedVersion` (or the previous version) with approve and reject (reason required by default).
|
|
96
|
+
- **`ArtifactVersionDiff`**: structural `ChangeSummary` list from `kind.diff` plus a highlighted or side-by-side line diff of the full projections.
|
|
97
|
+
|
|
98
|
+
## Editor host
|
|
99
|
+
|
|
100
|
+
Kind editors receive `EditorBindings` and only emit operations. `ArtifactEditor` (backed by the framework-free `EditorSession`) provides, for every kind:
|
|
101
|
+
|
|
102
|
+
1. **Grouping** — operations emitted with `{ kind: 'typing' }` are coalesced within `groupingWindowMs` (default 600 ms, capped at 5 s of continuous typing); discrete operations and the end of continuous gestures flush immediately. Typing is also flushed on blur and unmount.
|
|
103
|
+
2. **Optimistic apply** with the kind's own logic (`applyOperations`); invalid operations are rejected locally. Batches are sent one at a time with `baseVersion`. On rejection the editor rolls back to the last confirmed version and shows the error.
|
|
104
|
+
3. **Undo/redo** (buttons, `Ctrl/⌘+Z`, `Ctrl/⌘+Shift+Z`, `Ctrl+Y`) over the user's own batches. Kinds have no inverse operations, so **undo sends `replace_content` with the content before the batch** (plus `set_title`/`set_theme`/`set_locale` when those changed); each undo/redo is a new version (spec §8.5). When the artifact changed after the batch (e.g. the agent edited it), undo becomes a conflict instead of silently discarding the newer change.
|
|
105
|
+
4. **Concurrent edits** — newer versions arriving while editing rebase the pending local operations. On `VERSION_CONFLICT` (or a rebase that no longer applies) the editor shows what changed and offers **Keep agent version** or **Reapply my edit**.
|
|
106
|
+
5. **Locks** — a `LOCKED` rejection makes the editor read-only until the lock expires; the `lockedBy` prop does the same up front.
|
|
107
|
+
6. **Permissions** — `permission="read" | "edit"` (comment mode is phase 3).
|
|
108
|
+
7. **Accessibility** — keyboard operation, visible focus, live-region announcements (saved, undone, conflict, rejection).
|
|
109
|
+
|
|
110
|
+
Ids generated by the server for operations without explicit ids match the local ones only when nothing else changed in between; editors should pass explicit ids for new items.
|
|
111
|
+
|
|
112
|
+
## Hooks
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const { artifact, loading, error, refresh } = useArtifact(id, { version, initial });
|
|
116
|
+
const { entries, hasMore, loadMore, restore } = useArtifactHistory(id);
|
|
117
|
+
const { apply, pending, error, conflict, retry } = useApplyOperations(id);
|
|
118
|
+
const { exportArtifact, formats, loadFormats, warnings } = useArtifactExport(id);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
- `useArtifact` shares a cache per client. Specific versions are immutable and never refetched; the latest version is revalidated on mount and moves forward with every commit made through the hooks/components.
|
|
122
|
+
- `useApplyOperations` sends `baseVersion` (default: latest cached) and an idempotency key; on `VERSION_CONFLICT` it exposes `conflict.changes` and `retry()` on the latest version.
|
|
123
|
+
- `useArtifactExport` exports in the browser when a loaded exporter with runtime `any`/`browser` handles the format, otherwise calls `client.export`, then triggers a download (`download: false` to skip).
|
|
124
|
+
|
|
125
|
+
## Client
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
createHttpClient({ baseUrl = '/api/artifacts', fetch?, headers?, credentials? });
|
|
129
|
+
createServiceClient(service, scope /* or () => scope */);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Both implement `ArtifactClient`: `list`, `create`, `get`, `read`, `apply`, `preview`, `history`, `restore`, `setStatus(id, action, message?)`, `lock`, `unlock`, `export → { bytes, mimeType, filename, warnings }`. The HTTP client follows the contract in `docs/CONVENTIONS.md` and turns error responses back into `ArtifactError` (`code`, `issues`, `details`; status-based fallback when the body is not a payload). For cross-origin APIs expose `Content-Disposition` and `X-Artkit-Warnings` through `Access-Control-Expose-Headers`.
|
|
133
|
+
|
|
134
|
+
## Styling
|
|
135
|
+
|
|
136
|
+
All classes use the `ak-` prefix and colors come from CSS variables (`--ak-color-accent`, `--ak-font-body`…) derived from the artifact and application themes via `themeCssVariables`. The provider injects `<style>` elements (React 19 hoisted and deduplicated, so each is added once) with `artkitCss`, the theme variables (light, plus dark derived automatically or from `darkThemes`) and each loaded kind's CSS. Dark mode follows `prefers-color-scheme` unless `data-theme="light"|"dark"` is set on an ancestor or through `colorScheme`.
|
|
137
|
+
|
|
138
|
+
Every component accepts `className` and `slots` — per-part `{ className, style }` overrides (e.g. `slots={{ body: { className: 'my-body' } }}`) — so it can be customized without forking. Apps that ship their own CSS can pass `injectStyles={false}` and import `artkitCss`/`themeStyles`.
|
|
139
|
+
|
|
140
|
+
## i18n
|
|
141
|
+
|
|
142
|
+
UI strings ship in pt-BR and en (`uiMessages`); `locale` picks the catalog (`pt*` → pt-BR, anything else → en) and `messages` adds or overrides strings for any locale. Dates use `Intl` with the UI locale; artifact content keeps the artifact's own `locale`.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
Apache-2.0
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Artifact } from '@artkit-ai/core';
|
|
2
|
+
import type { ArtifactClient } from './client.js';
|
|
3
|
+
export interface CacheEntry {
|
|
4
|
+
artifact?: Artifact;
|
|
5
|
+
error?: unknown;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Artifact cache shared by the hooks under one provider (spec §13.2). Versions are immutable, so an
|
|
10
|
+
* entry for a specific version never needs revalidation; the `latest` entry only moves forward and is
|
|
11
|
+
* revalidated on demand. Listeners are per artifact id so history and editors hear about new commits.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ArtifactCache {
|
|
14
|
+
private readonly client;
|
|
15
|
+
private readonly entries;
|
|
16
|
+
private readonly inflight;
|
|
17
|
+
private readonly listeners;
|
|
18
|
+
constructor(client: ArtifactClient);
|
|
19
|
+
entry(id: string, version?: number): CacheEntry;
|
|
20
|
+
latest(id: string): Artifact | undefined;
|
|
21
|
+
subscribe(id: string, listener: () => void): () => void;
|
|
22
|
+
private notify;
|
|
23
|
+
private set;
|
|
24
|
+
/**
|
|
25
|
+
* Records a known artifact version (commit result, prop, status change). `latest` only moves forward,
|
|
26
|
+
* except that a status change on the same version replaces it.
|
|
27
|
+
*/
|
|
28
|
+
put(artifact: Artifact): void;
|
|
29
|
+
/** Loads unless a fresh value is cached. `force` revalidates `latest` (specific versions never change). */
|
|
30
|
+
load(id: string, version?: number, force?: boolean): Promise<Artifact>;
|
|
31
|
+
/** Signals listeners of an id without changing entries (e.g. history must refetch after a restore). */
|
|
32
|
+
touch(id: string): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function cacheFor(client: ArtifactClient): ArtifactCache;
|
|
35
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AAMD;;;;GAIG;AACH,qBAAa,aAAa;IAKZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAEhE,YAA6B,MAAM,EAAE,cAAc,EAAI;IAEvD,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAE9C;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAEvC;IAED,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAQtD;IAED,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,GAAG;IAIX;;;OAGG;IACH,GAAG,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAe5B;IAED,2GAA2G;IAC3G,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyCnE;IAED,uGAAuG;IACvG,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAEtB;CACF;AAID,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,aAAa,CAO9D"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const EMPTY = Object.freeze({ loading: false });
|
|
2
|
+
const keyOf = (id, version) => `${id}@${version ?? 'latest'}`;
|
|
3
|
+
/**
|
|
4
|
+
* Artifact cache shared by the hooks under one provider (spec §13.2). Versions are immutable, so an
|
|
5
|
+
* entry for a specific version never needs revalidation; the `latest` entry only moves forward and is
|
|
6
|
+
* revalidated on demand. Listeners are per artifact id so history and editors hear about new commits.
|
|
7
|
+
*/
|
|
8
|
+
export class ArtifactCache {
|
|
9
|
+
client;
|
|
10
|
+
entries = new Map();
|
|
11
|
+
inflight = new Map();
|
|
12
|
+
listeners = new Map();
|
|
13
|
+
constructor(client) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
}
|
|
16
|
+
entry(id, version) {
|
|
17
|
+
return this.entries.get(keyOf(id, version)) ?? EMPTY;
|
|
18
|
+
}
|
|
19
|
+
latest(id) {
|
|
20
|
+
return this.entries.get(keyOf(id))?.artifact;
|
|
21
|
+
}
|
|
22
|
+
subscribe(id, listener) {
|
|
23
|
+
const set = this.listeners.get(id) ?? new Set();
|
|
24
|
+
set.add(listener);
|
|
25
|
+
this.listeners.set(id, set);
|
|
26
|
+
return () => {
|
|
27
|
+
set.delete(listener);
|
|
28
|
+
if (set.size === 0)
|
|
29
|
+
this.listeners.delete(id);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
notify(id) {
|
|
33
|
+
for (const listener of [...(this.listeners.get(id) ?? [])])
|
|
34
|
+
listener();
|
|
35
|
+
}
|
|
36
|
+
set(id, version, entry) {
|
|
37
|
+
this.entries.set(keyOf(id, version), entry);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Records a known artifact version (commit result, prop, status change). `latest` only moves forward,
|
|
41
|
+
* except that a status change on the same version replaces it.
|
|
42
|
+
*/
|
|
43
|
+
put(artifact) {
|
|
44
|
+
const current = this.latest(artifact.id);
|
|
45
|
+
const sameVersionChanged = current !== undefined &&
|
|
46
|
+
artifact.version === current.version &&
|
|
47
|
+
(artifact.status !== current.status ||
|
|
48
|
+
artifact.meta.updatedAt !== current.meta.updatedAt ||
|
|
49
|
+
artifact.meta.publishedVersion !== current.meta.publishedVersion);
|
|
50
|
+
const known = this.entries.get(keyOf(artifact.id, artifact.version))?.artifact;
|
|
51
|
+
if (current && !sameVersionChanged && artifact.version <= current.version && known)
|
|
52
|
+
return;
|
|
53
|
+
this.set(artifact.id, artifact.version, { artifact, loading: false });
|
|
54
|
+
if (!current || artifact.version > current.version || sameVersionChanged) {
|
|
55
|
+
this.set(artifact.id, undefined, { artifact, loading: false });
|
|
56
|
+
}
|
|
57
|
+
this.notify(artifact.id);
|
|
58
|
+
}
|
|
59
|
+
/** Loads unless a fresh value is cached. `force` revalidates `latest` (specific versions never change). */
|
|
60
|
+
load(id, version, force = false) {
|
|
61
|
+
const key = keyOf(id, version);
|
|
62
|
+
const existing = this.entries.get(key);
|
|
63
|
+
if (existing?.artifact && (version !== undefined || !force))
|
|
64
|
+
return Promise.resolve(existing.artifact);
|
|
65
|
+
const pending = this.inflight.get(key);
|
|
66
|
+
if (pending)
|
|
67
|
+
return pending;
|
|
68
|
+
this.set(id, version, { ...(existing ?? {}), loading: true });
|
|
69
|
+
this.notify(id);
|
|
70
|
+
const promise = this.client.get(id, version === undefined ? undefined : { version }).then((artifact) => {
|
|
71
|
+
this.inflight.delete(key);
|
|
72
|
+
if (version === undefined) {
|
|
73
|
+
// A commit may have landed while the request was in flight; never move `latest` backwards.
|
|
74
|
+
const current = this.latest(id);
|
|
75
|
+
if (current && current.version > artifact.version) {
|
|
76
|
+
this.set(id, undefined, { artifact: current, loading: false });
|
|
77
|
+
this.notify(id);
|
|
78
|
+
return current;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.set(artifact.id, artifact.version, { artifact, loading: false });
|
|
82
|
+
if (version === undefined)
|
|
83
|
+
this.set(id, undefined, { artifact, loading: false });
|
|
84
|
+
else if (!this.latest(id) || this.latest(id).version < artifact.version)
|
|
85
|
+
this.set(id, undefined, { artifact, loading: false });
|
|
86
|
+
this.notify(id);
|
|
87
|
+
return artifact;
|
|
88
|
+
}, (error) => {
|
|
89
|
+
this.inflight.delete(key);
|
|
90
|
+
const previous = this.entries.get(key);
|
|
91
|
+
this.set(id, version, {
|
|
92
|
+
...(previous?.artifact ? { artifact: previous.artifact } : {}),
|
|
93
|
+
error,
|
|
94
|
+
loading: false,
|
|
95
|
+
});
|
|
96
|
+
this.notify(id);
|
|
97
|
+
throw error;
|
|
98
|
+
});
|
|
99
|
+
this.inflight.set(key, promise);
|
|
100
|
+
return promise;
|
|
101
|
+
}
|
|
102
|
+
/** Signals listeners of an id without changing entries (e.g. history must refetch after a restore). */
|
|
103
|
+
touch(id) {
|
|
104
|
+
this.notify(id);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const caches = new WeakMap();
|
|
108
|
+
export function cacheFor(client) {
|
|
109
|
+
let cache = caches.get(client);
|
|
110
|
+
if (!cache) {
|
|
111
|
+
cache = new ArtifactCache(client);
|
|
112
|
+
caches.set(client, cache);
|
|
113
|
+
}
|
|
114
|
+
return cache;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AASA,MAAM,KAAK,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAe,CAAC;AAE1E,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,OAAgB,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,OAAO,IAAI,QAAQ,EAAE,CAAC;AAE/E;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAKK,MAAM;IAJlB,OAAO,GAAG,IAAI,GAAG,EAAsB,CAAC;IACxC,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;IAChD,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEhE,YAA6B,MAAsB;sBAAtB,MAAM;IAAmB,CAAC;IAEvD,KAAK,CAAC,EAAU,EAAE,OAAgB;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC;IACvD,CAAC;IAED,MAAM,CAAC,EAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,EAAU,EAAE,QAAoB;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;QAChD,GA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{ type Artifact, ArtifactError, type ArtifactFilter, type ArtifactService, type ArtifactSummary, type BatchResult, type CommitResult, type CreateRequest, type Lock, type Page, type PageRequest, type ProjectionMode, type ReadResult, type Scope, type VersionEntry } from '@artkit-ai/core';
|
|
2
|
+
/** Lifecycle actions accepted by `POST {base}/{id}/status` (spec §15.3). */
|
|
3
|
+
export type StatusAction = 'submit' | 'approve' | 'reject' | 'publish' | 'archive';
|
|
4
|
+
export declare const STATUS_ACTIONS: readonly StatusAction[];
|
|
5
|
+
export interface RequestOptions {
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export interface ReadOptions extends RequestOptions {
|
|
9
|
+
mode?: ProjectionMode;
|
|
10
|
+
range?: string;
|
|
11
|
+
maxTokens?: number;
|
|
12
|
+
cursor?: string;
|
|
13
|
+
version?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ApplyInput {
|
|
16
|
+
baseVersion: number;
|
|
17
|
+
operations: unknown[];
|
|
18
|
+
idempotencyKey?: string;
|
|
19
|
+
message?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ExportInput extends RequestOptions {
|
|
22
|
+
format: string;
|
|
23
|
+
version?: number;
|
|
24
|
+
options?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export interface ClientExportResult {
|
|
27
|
+
bytes: Uint8Array;
|
|
28
|
+
mimeType: string;
|
|
29
|
+
filename: string;
|
|
30
|
+
warnings: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What the React layer talks to (spec §13.3). It never touches a store: credentials and authorization
|
|
34
|
+
* stay on the server (HTTP client) or in the scope given to an in-process service (service client).
|
|
35
|
+
*/
|
|
36
|
+
export interface ArtifactClient {
|
|
37
|
+
list(filter?: ArtifactFilter, page?: PageRequest, options?: RequestOptions): Promise<Page<ArtifactSummary>>;
|
|
38
|
+
create(request: CreateRequest, options?: RequestOptions): Promise<CommitResult>;
|
|
39
|
+
get(id: string, options?: RequestOptions & {
|
|
40
|
+
version?: number;
|
|
41
|
+
}): Promise<Artifact>;
|
|
42
|
+
read(id: string, options?: ReadOptions): Promise<ReadResult>;
|
|
43
|
+
apply(id: string, input: ApplyInput, options?: RequestOptions): Promise<CommitResult>;
|
|
44
|
+
/** Dry run on the current version: diff and lint without committing. */
|
|
45
|
+
preview(id: string, input: ApplyInput, options?: RequestOptions): Promise<BatchResult>;
|
|
46
|
+
history(id: string, page?: PageRequest, options?: RequestOptions): Promise<Page<VersionEntry>>;
|
|
47
|
+
restore(id: string, version: number, message?: string, options?: RequestOptions): Promise<CommitResult>;
|
|
48
|
+
setStatus(id: string, action: StatusAction, message?: string, options?: RequestOptions): Promise<Artifact>;
|
|
49
|
+
lock(id: string, options?: RequestOptions & {
|
|
50
|
+
ttlMs?: number;
|
|
51
|
+
}): Promise<Lock>;
|
|
52
|
+
unlock(id: string, lock: Lock, options?: RequestOptions): Promise<void>;
|
|
53
|
+
/** Current lock, or null when nobody holds one. */
|
|
54
|
+
getLock(id: string, options?: RequestOptions): Promise<Lock | null>;
|
|
55
|
+
export(id: string, input: ExportInput): Promise<ClientExportResult>;
|
|
56
|
+
}
|
|
57
|
+
type HeadersSource = HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
58
|
+
export interface HttpClientOptions {
|
|
59
|
+
/** Base path of the `@artkit-ai/node` routes (default `/api/artifacts`). */
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
/** Custom fetch (auth wrappers, tests, SSR). Defaults to the global `fetch`. */
|
|
62
|
+
fetch?: typeof fetch;
|
|
63
|
+
/** Extra headers, or a function returning them per request (e.g. a fresh bearer token). */
|
|
64
|
+
headers?: HeadersSource;
|
|
65
|
+
credentials?: RequestCredentials;
|
|
66
|
+
}
|
|
67
|
+
/** Rebuilds an `ArtifactError` from an HTTP error response (`ModelErrorPayload` body, spec CONVENTIONS). */
|
|
68
|
+
export declare function errorFromResponse(response: Response): Promise<ArtifactError>;
|
|
69
|
+
/** Parses `Content-Disposition`, preferring the RFC 5987 `filename*` form. */
|
|
70
|
+
export declare function filenameFromDisposition(header: string | null): string | undefined;
|
|
71
|
+
/** Reference client for the `@artkit-ai/node` routes (HTTP contract in docs/CONVENTIONS.md). */
|
|
72
|
+
export declare function createHttpClient(options?: HttpClientOptions): ArtifactClient;
|
|
73
|
+
/**
|
|
74
|
+
* Wraps a core `ArtifactService` in-process (playground, tests, local apps). The scope is fixed by the
|
|
75
|
+
* application, never by the UI; pass a function to resolve it per call (e.g. after a login change).
|
|
76
|
+
*/
|
|
77
|
+
export declare function createServiceClient(service: ArtifactService, scope: Scope | (() => Scope)): ArtifactClient;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,aAAa,EAKlB,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAC;AAEzB,4EAA4E;AAC5E,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAEnF,eAAO,MAAM,cAAc,EAAE,SAAS,YAAY,EAA0D,CAAC;AAE7G,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,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