@aparte/plugin-artifacts 0.16.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 +21 -0
- package/README.md +60 -0
- package/dist/binary-file.d.ts +7 -0
- package/dist/binary-file.d.ts.map +1 -0
- package/dist/card.d.ts +6 -0
- package/dist/card.d.ts.map +1 -0
- package/dist/custom-elements.json +1184 -0
- package/dist/highlight.d.ts +17 -0
- package/dist/highlight.d.ts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +675 -0
- package/dist/index.js.map +1 -0
- package/dist/index.node.d.ts +32 -0
- package/dist/index.node.d.ts.map +1 -0
- package/dist/index.node.js +30 -0
- package/dist/index.node.js.map +1 -0
- package/dist/kinds.d.ts +19 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/options.d.ts +72 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/preview-document-xP-Ne-F0.js +177 -0
- package/dist/preview-document-xP-Ne-F0.js.map +1 -0
- package/dist/preview-document.d.ts +27 -0
- package/dist/preview-document.d.ts.map +1 -0
- package/dist/segment.d.ts +66 -0
- package/dist/segment.d.ts.map +1 -0
- package/dist/shared.d.ts +29 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/tool.d.ts +31 -0
- package/dist/tool.d.ts.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 aparté
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @aparte/plugin-artifacts
|
|
2
|
+
|
|
3
|
+
Artifacts for [aparté](https://github.com/apartejs/aparte): a document the model produces — a page, a
|
|
4
|
+
component, a script, an SVG, a Markdown note, a spreadsheet — shown as a Code/Preview card in the
|
|
5
|
+
transcript. An artifact is a convention an app teaches its model, not something a model does by
|
|
6
|
+
nature, so the whole convention lives here: the `create_artifact` **tool** the model calls, the
|
|
7
|
+
**card** that renders its result, and the `<artifact>` **tag grammar** for a model that writes one
|
|
8
|
+
in its prose.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @aparte/plugin-artifacts @aparte/core
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { setupArtifacts } from '@aparte/plugin-artifacts';
|
|
16
|
+
|
|
17
|
+
setupArtifacts(); // registers the tool, its renderer, the grammar and the segment renderer
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`@aparte/core` is the only **peer dependency**.
|
|
21
|
+
|
|
22
|
+
## Options
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
setupArtifacts({
|
|
26
|
+
name: 'create_artifact', // the tool's name as the model sees it
|
|
27
|
+
systemPrompt: false, // your own string, or false to send none
|
|
28
|
+
tag: 'artifact', // the tag recognised in the prose; false for none
|
|
29
|
+
preview: true, // false: no Preview tab; a function: your own srcdoc builder
|
|
30
|
+
onBinary: async (artifact) => { // pdf / xlsx / docx: produce the file from the model's source
|
|
31
|
+
const { buffer, filename } = await runInYourSandbox(artifact.content);
|
|
32
|
+
return { buffer, filename, mime: artifact.mimeType };
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
A second argument scopes everything to one `AparteConfig` instead of the global one. The call
|
|
38
|
+
returns a function that unregisters all four.
|
|
39
|
+
|
|
40
|
+
## What the card does
|
|
41
|
+
|
|
42
|
+
- Opens on **Code**, highlighted through whatever highlighter core was given.
|
|
43
|
+
- **Preview** — for `html`, `react`, `svg`, `js` and `css` — is mounted only when the reader
|
|
44
|
+
presses the tab: a previewable artifact is model-authored code, and mounting it unasked
|
|
45
|
+
executes it. The frame is `sandbox="allow-scripts"` with a CSP that lets nothing out.
|
|
46
|
+
- **Copy** and **Download** on every text artifact; a binary one (`pdf`, `xlsx`, `docx`)
|
|
47
|
+
downloads only once your `onBinary` produced it — without one there is no button, because
|
|
48
|
+
the library holds no bytes.
|
|
49
|
+
|
|
50
|
+
## Two ways in, one card
|
|
51
|
+
|
|
52
|
+
A model with tools calls `create_artifact` with `{ mimeType, title, content }`; the handler
|
|
53
|
+
returns the document as the tool's structured result and the card is drawn from it. A model
|
|
54
|
+
without tools writes `<artifact type="text/html" title="…">…</artifact>` in its reply; core's
|
|
55
|
+
parser — taught the grammar by this plugin through `registerStreamBlock` — streams it into an
|
|
56
|
+
`artifact` segment the same card renders.
|
|
57
|
+
|
|
58
|
+
MIME types follow the standard, plus Anthropic's `application/vnd.ant.*` namespace for
|
|
59
|
+
framework kinds (`application/vnd.ant.react`). `deriveArtifactKind(mimeType)` gives the short
|
|
60
|
+
kind the card switches on.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ArtifactSegment } from './segment.js';
|
|
2
|
+
/** For tests: forget every produced file and every generation in flight. */
|
|
3
|
+
export declare function resetBinaryArtifacts(): void;
|
|
4
|
+
export declare function renderBinaryFileArtifact(segment: ArtifactSegment, kind: string): string;
|
|
5
|
+
export declare function setupBinaryFileArtifact(element: HTMLElement, segment: ArtifactSegment, kind: string): void;
|
|
6
|
+
export declare function updateBinaryFileArtifact(element: HTMLElement, segment: ArtifactSegment, isStreaming: boolean): void;
|
|
7
|
+
//# sourceMappingURL=binary-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-file.d.ts","sourceRoot":"","sources":["../src/binary-file.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AA8BpD,4EAA4E;AAC5E,wBAAgB,oBAAoB,IAAI,IAAI,CAG3C;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAgEvF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAa1G;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,OAAO,GAAG,IAAI,CAYnH"}
|
package/dist/card.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AparteSegmentRenderer } from '@aparte/core';
|
|
2
|
+
import { type ArtifactSegment } from './segment.js';
|
|
3
|
+
/** The segment shape the card draws — exported for a consumer's own tests and renderers. */
|
|
4
|
+
export type AparteArtifactSegment = ArtifactSegment;
|
|
5
|
+
export declare const artifactRenderer: AparteSegmentRenderer<ArtifactSegment>;
|
|
6
|
+
//# sourceMappingURL=card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../src/card.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAa3E,4FAA4F;AAC5F,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAYpD,eAAO,MAAM,gBAAgB,EAAE,qBAAqB,CAAC,eAAe,CAoSnE,CAAC"}
|