@slexkit/assistant-ui 0.4.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) SlexKit contributors
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,117 @@
1
+ # @slexkit/assistant-ui
2
+
3
+ assistant-ui Streamdown text renderer for SlexKit fenced artifact blocks.
4
+
5
+ Use this package when assistant-ui message text already renders through
6
+ `@assistant-ui/react-streamdown`. It replaces explicit `slex` fenced code blocks
7
+ inside assistant message text; threads, messages, composer, runtime, and tool UI
8
+ stay with assistant-ui.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ npm install slexkit @slexkit/theme-shadcn @slexkit/streamdown @slexkit/assistant-ui @assistant-ui/react @assistant-ui/react-streamdown streamdown react react-dom
14
+ ```
15
+
16
+ Import styles once in the app:
17
+
18
+ ```ts
19
+ import "@slexkit/theme-shadcn/style.css";
20
+ import "@slexkit/assistant-ui/style.css";
21
+ ```
22
+
23
+ ## Minimal Usage
24
+
25
+ Use the component where assistant-ui renders message text parts:
26
+
27
+ ```tsx
28
+ import { MessagePrimitive } from "@assistant-ui/react";
29
+ import { SlexKitAssistantStreamdownText } from "@slexkit/assistant-ui";
30
+
31
+ export function AssistantMessage() {
32
+ return (
33
+ <MessagePrimitive.Root>
34
+ <MessagePrimitive.Parts>
35
+ {({ part }) =>
36
+ part.type === "text" ? (
37
+ <SlexKitAssistantStreamdownText
38
+ artifactId="message-1"
39
+ runtime="secure"
40
+ secureFrame={{ runtimeUrl: "/slexkit.runtime.js" }}
41
+ />
42
+ ) : null
43
+ }
44
+ </MessagePrimitive.Parts>
45
+ </MessagePrimitive.Root>
46
+ );
47
+ }
48
+ ```
49
+
50
+ For app-authored, reviewed content, trusted mode can be enabled:
51
+
52
+ ```tsx
53
+ <SlexKitAssistantStreamdownText artifactId="message-1" runtime="trusted" />
54
+ ```
55
+
56
+ ## Existing StreamdownTextPrimitive
57
+
58
+ For an existing `StreamdownTextPrimitive` wrapper, merge only the SlexKit
59
+ language override:
60
+
61
+ ```tsx
62
+ import { StreamdownTextPrimitive } from "@assistant-ui/react-streamdown";
63
+ import { createSlexKitAssistantStreamdownComponents } from "@slexkit/assistant-ui";
64
+
65
+ const componentsByLanguage = createSlexKitAssistantStreamdownComponents({
66
+ artifactId: "message-1",
67
+ runtime: "secure",
68
+ secureFrame: { runtimeUrl: "/slexkit.runtime.js" },
69
+ });
70
+
71
+ export function MarkdownText() {
72
+ return <StreamdownTextPrimitive componentsByLanguage={componentsByLanguage} />;
73
+ }
74
+ ```
75
+
76
+ ## Model Output
77
+
78
+ Ask the model to emit Slex only in explicit `slex` fenced blocks. Ordinary
79
+ Markdown and non-`slex` code blocks stay with assistant-ui's Streamdown renderer.
80
+
81
+ ````md
82
+ ```slex
83
+ {
84
+ namespace: "status_demo",
85
+ g: {},
86
+ layout: {
87
+ "text:status": { text: "3/4 checks complete" }
88
+ }
89
+ }
90
+ ```
91
+
92
+ **Status:** 3/4 checks complete
93
+ ````
94
+
95
+ ## Trust Boundary
96
+
97
+ The default runtime is `secure`, because assistant messages often contain direct
98
+ model output. Secure mode requires a public SlexKit runtime module:
99
+
100
+ ```sh
101
+ npx -y slexkit copy-runtime public/slexkit.runtime.js
102
+ ```
103
+
104
+ Serve that file with:
105
+
106
+ ```http
107
+ Access-Control-Allow-Origin: *
108
+ Content-Type: text/javascript
109
+ ```
110
+
111
+ Use `runtime="trusted"` only for content authored or reviewed by the application.
112
+
113
+ ## ToolHost
114
+
115
+ This package handles message text only. assistant-ui tool calls, approvals, and
116
+ form submissions need their own integration. Use ToolHost for structured
117
+ user-return flows.
@@ -0,0 +1,34 @@
1
+ import type { ComponentsByLanguage, StreamdownTextPrimitiveProps, SyntaxHighlighterProps } from "@assistant-ui/react-streamdown";
2
+ import type { SlexKitRendererOptions } from "@slexkit/streamdown";
3
+ export type SlexKitAssistantRendererOptions = Omit<SlexKitRendererOptions, "className" | "domain" | "languages"> & {
4
+ artifactId?: string;
5
+ className?: string;
6
+ domain?: string;
7
+ };
8
+ export type SlexKitAssistantStreamdownTextProps = Omit<StreamdownTextPrimitiveProps, "componentsByLanguage"> & SlexKitAssistantRendererOptions & {
9
+ componentsByLanguage?: ComponentsByLanguage;
10
+ slexkit?: SlexKitAssistantRendererOptions;
11
+ };
12
+ export declare function createSlexKitAssistantStreamdownComponents(options?: SlexKitAssistantRendererOptions, componentsByLanguage?: ComponentsByLanguage): ComponentsByLanguage;
13
+ export declare function SlexKitAssistantStreamdownText({ artifactId, className, componentsByLanguage, domain, hostAdapter, onError, placeholder, playgroundUrl, renderMode, runtime, runtimeHost, secureFrame, securePolicy, showChrome, showSource, slexkit, streaming, useGlobalRuntimeHost, ...streamdownProps }: SlexKitAssistantStreamdownTextProps): import("react").FunctionComponentElement<Omit<import("streamdown").StreamdownProps, "children" | "components" | "plugins" | "caret" | "controls" | "linkSafety" | "remend" | "mermaid" | "BlockComponent" | "parseMarkdownIntoBlocksFn"> & {
14
+ components?: import("@assistant-ui/react-streamdown").StreamdownTextComponents | undefined;
15
+ componentsByLanguage?: ComponentsByLanguage | undefined;
16
+ plugins?: import("@assistant-ui/react-streamdown").PluginConfig | undefined;
17
+ preprocess?: ((text: string) => string) | undefined;
18
+ defer?: boolean | undefined;
19
+ smooth?: boolean | import("@assistant-ui/react").SmoothOptions | undefined;
20
+ containerProps?: Omit<import("react").ComponentPropsWithoutRef<"div">, "children"> | undefined;
21
+ containerClassName?: string | undefined;
22
+ caret?: import("@assistant-ui/react-streamdown").CaretStyle | undefined;
23
+ controls?: import("@assistant-ui/react-streamdown").ControlsConfig | undefined;
24
+ linkSafety?: import("@assistant-ui/react-streamdown").LinkSafetyConfig | undefined;
25
+ remend?: import("@assistant-ui/react-streamdown").RemendConfig | undefined;
26
+ mermaid?: import("streamdown").MermaidOptions | undefined;
27
+ parseIncompleteMarkdown?: boolean | undefined;
28
+ allowedTags?: import("@assistant-ui/react-streamdown").AllowedTags | undefined;
29
+ remarkRehypeOptions?: import("@assistant-ui/react-streamdown").Options | undefined;
30
+ security?: import("@assistant-ui/react-streamdown").SecurityConfig | undefined;
31
+ BlockComponent?: import("streamdown").StreamdownProps["BlockComponent"] | undefined;
32
+ parseMarkdownIntoBlocksFn?: ((markdown: string) => string[]) | undefined;
33
+ } & import("react").RefAttributes<HTMLDivElement>>;
34
+ export type { ComponentsByLanguage, StreamdownTextPrimitiveProps, SyntaxHighlighterProps, };
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ import { StreamdownTextPrimitive } from "@assistant-ui/react-streamdown";
2
+ import { SlexKitRenderer } from "@slexkit/streamdown";
3
+ import { createElement, useId, useMemo } from "react";
4
+ function normalizeSlexKitOptions(options = {}) {
5
+ const { artifactId, domain, runtime, showChrome, ...rest } = options;
6
+ return {
7
+ ...rest,
8
+ domain: domain ?? artifactId,
9
+ runtime: runtime ?? "secure",
10
+ showChrome: showChrome ?? false,
11
+ };
12
+ }
13
+ function createSlexKitSyntaxHighlighter(options = {}) {
14
+ const rendererOptions = normalizeSlexKitOptions(options);
15
+ return function SlexKitAssistantSyntaxHighlighter({ code, language, }) {
16
+ return createElement(SlexKitRenderer, {
17
+ ...rendererOptions,
18
+ code,
19
+ isIncomplete: false,
20
+ language: language || "slex",
21
+ });
22
+ };
23
+ }
24
+ export function createSlexKitAssistantStreamdownComponents(options = {}, componentsByLanguage = {}) {
25
+ return {
26
+ ...componentsByLanguage,
27
+ slex: {
28
+ ...componentsByLanguage.slex,
29
+ CodeHeader: componentsByLanguage.slex?.CodeHeader ?? (() => null),
30
+ SyntaxHighlighter: createSlexKitSyntaxHighlighter(options),
31
+ },
32
+ };
33
+ }
34
+ export function SlexKitAssistantStreamdownText({ artifactId, className, componentsByLanguage, domain, hostAdapter, onError, placeholder, playgroundUrl, renderMode, runtime, runtimeHost, secureFrame, securePolicy, showChrome, showSource, slexkit, streaming, useGlobalRuntimeHost, ...streamdownProps }) {
35
+ const generatedId = useId();
36
+ const resolvedArtifactId = artifactId ?? domain ?? `slexkit-assistant-${generatedId}`;
37
+ const resolvedComponentsByLanguage = useMemo(() => createSlexKitAssistantStreamdownComponents({
38
+ artifactId: resolvedArtifactId,
39
+ className,
40
+ domain,
41
+ hostAdapter,
42
+ onError,
43
+ placeholder,
44
+ playgroundUrl,
45
+ renderMode,
46
+ runtime,
47
+ runtimeHost,
48
+ secureFrame,
49
+ securePolicy,
50
+ showChrome,
51
+ showSource,
52
+ streaming,
53
+ useGlobalRuntimeHost,
54
+ ...slexkit,
55
+ }, componentsByLanguage), [
56
+ className,
57
+ componentsByLanguage,
58
+ domain,
59
+ hostAdapter,
60
+ onError,
61
+ placeholder,
62
+ playgroundUrl,
63
+ renderMode,
64
+ resolvedArtifactId,
65
+ runtime,
66
+ runtimeHost,
67
+ secureFrame,
68
+ securePolicy,
69
+ showChrome,
70
+ showSource,
71
+ slexkit,
72
+ streaming,
73
+ useGlobalRuntimeHost,
74
+ ]);
75
+ return createElement(StreamdownTextPrimitive, {
76
+ ...streamdownProps,
77
+ componentsByLanguage: resolvedComponentsByLanguage,
78
+ });
79
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@slexkit/assistant-ui",
3
+ "version": "0.4.0",
4
+ "description": "assistant-ui Streamdown text renderer for SlexKit fenced artifact blocks.",
5
+ "author": "SlexKit contributors",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/slexkit/slexkit.git",
10
+ "directory": "packages/assistant-ui"
11
+ },
12
+ "homepage": "https://github.com/slexkit/slexkit/tree/main/packages/assistant-ui#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/slexkit/slexkit/issues"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ },
24
+ "./style.css": "./style.css"
25
+ },
26
+ "files": [
27
+ "dist/",
28
+ "style.css",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "sideEffects": [
33
+ "./style.css"
34
+ ],
35
+ "scripts": {
36
+ "build": "bun run scripts/build.ts"
37
+ },
38
+ "keywords": [
39
+ "slexkit",
40
+ "assistant-ui",
41
+ "react",
42
+ "streamdown",
43
+ "markdown",
44
+ "renderer"
45
+ ],
46
+ "license": "MIT",
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "peerDependencies": {
51
+ "@assistant-ui/react": "^0.14.23",
52
+ "@assistant-ui/react-streamdown": "^0.3.4",
53
+ "@slexkit/streamdown": "^0.4.0",
54
+ "react": "^18.0.0 || ^19.0.0",
55
+ "react-dom": "^18.0.0 || ^19.0.0",
56
+ "slexkit": "^0.4.0",
57
+ "streamdown": "^2.5.0"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "slexkit": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "devDependencies": {
65
+ "@assistant-ui/react": "^0.14.23",
66
+ "@assistant-ui/react-streamdown": "^0.3.4",
67
+ "@slexkit/streamdown": "workspace:*",
68
+ "@types/react": "^19.2.7",
69
+ "@types/react-dom": "^19.2.3",
70
+ "react": "^19.2.6",
71
+ "react-dom": "^19.2.6",
72
+ "streamdown": "^2.5.0"
73
+ }
74
+ }
package/style.css ADDED
@@ -0,0 +1 @@
1
+ @import "@slexkit/streamdown/style.css";