@aqian0/dsh-renderer 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 +21 -0
- package/README.md +122 -2
- package/cordis.patch.yml +4 -0
- package/icon.svg +5 -0
- package/lib/client.js +789 -0
- package/lib/config.js +96 -0
- package/lib/host/artifact-skill.js +55 -0
- package/lib/host/artifact-tool.js +177 -0
- package/lib/host/media-bridge.js +102 -0
- package/lib/index.js +120 -0
- package/lib/shared/artifact-stream.js +293 -0
- package/lib/shared/config-defaults.js +92 -0
- package/lib/shared/content-complexity.js +812 -0
- package/lib/shared/media-extractor.js +154 -0
- package/lib/shared/sandbox-core.js +286 -0
- package/lib/shared/sanitize.js +539 -0
- package/lib/types/client/artifact-node.d.ts +62 -0
- package/lib/types/client/artifact-resource.d.ts +30 -0
- package/lib/types/client/artifact-toolview.d.ts +17 -0
- package/lib/types/client/code-view.d.ts +22 -0
- package/lib/types/client/document-card.d.ts +33 -0
- package/lib/types/client/fence-layer.d.ts +26 -0
- package/lib/types/client/highlight.d.ts +24 -0
- package/lib/types/client/icons.d.ts +10 -0
- package/lib/types/client/locales.d.ts +57 -0
- package/lib/types/client/sandbox.d.ts +23 -0
- package/lib/types/client/styles.d.ts +20 -0
- package/lib/types/client/svg-view.d.ts +19 -0
- package/lib/types/client/theme.d.ts +20 -0
- package/lib/types/client/turn-media.d.ts +10 -0
- package/lib/types/client/types.d.ts +293 -0
- package/lib/types/client/workbench.d.ts +24 -0
- package/lib/types/client.d.ts +10 -0
- package/lib/types/config.d.ts +50 -0
- package/lib/types/host/artifact-skill.d.ts +39 -0
- package/lib/types/host/artifact-tool.d.ts +82 -0
- package/lib/types/host/media-bridge.d.ts +47 -0
- package/lib/types/index.d.ts +29 -0
- package/lib/types/shared/artifact-stream.d.ts +52 -0
- package/lib/types/shared/config-defaults.d.ts +56 -0
- package/lib/types/shared/content-complexity.d.ts +94 -0
- package/lib/types/shared/media-extractor.d.ts +42 -0
- package/lib/types/shared/sandbox-core.d.ts +128 -0
- package/lib/types/shared/sanitize.d.ts +97 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +95 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency HTML/SVG sanitizer, CSP builder, and sandbox document generator.
|
|
3
|
+
*
|
|
4
|
+
* Security is layered:
|
|
5
|
+
* 1. A character-level HTML tag/attribute scanner strips dangerous elements, event
|
|
6
|
+
* handlers, unsafe URI schemes, declarative shadow roots, and unsafe CSS constructs.
|
|
7
|
+
* 2. Every generated static or interactive document prepends a strict
|
|
8
|
+
* Content-Security-Policy `<meta>` element before any author markup.
|
|
9
|
+
* 3. Callers mount static previews inside `<iframe sandbox="">` and interactive
|
|
10
|
+
* previews inside a Blob URL `<iframe sandbox="allow-scripts">` (never
|
|
11
|
+
* `allow-same-origin`).
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-renderer/shared/sanitize
|
|
14
|
+
*/
|
|
15
|
+
/** Theme tokens injected into sandboxed HTML documents so previews follow light/dark mode. */
|
|
16
|
+
export interface SandboxThemeTokens {
|
|
17
|
+
readonly scheme: 'light' | 'dark';
|
|
18
|
+
readonly bg: string;
|
|
19
|
+
readonly fg: string;
|
|
20
|
+
readonly border: string;
|
|
21
|
+
readonly accent: string;
|
|
22
|
+
}
|
|
23
|
+
/** Options controlling HTML sanitization and CSP generation. */
|
|
24
|
+
export interface HtmlDocumentOptions {
|
|
25
|
+
/** Allow external HTTPS stylesheets, scripts (in interactive mode), images, and fonts. */
|
|
26
|
+
readonly allowExternalResources: boolean;
|
|
27
|
+
/** Optional host theme tokens mirrored into the document `:root`. */
|
|
28
|
+
readonly theme?: SandboxThemeTokens | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Optional per-instance bridge pair (`token` + cryptographic `nonce`) enabling
|
|
31
|
+
* exact content-height measurement and live theme sync in static mode while
|
|
32
|
+
* keeping all author scripts strictly forbidden via `script-src 'nonce-...'`.
|
|
33
|
+
*/
|
|
34
|
+
readonly staticBridge?: {
|
|
35
|
+
readonly token: string;
|
|
36
|
+
readonly nonce: string;
|
|
37
|
+
} | undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Additional options for interactive sandbox documents with height/theme postMessage bridging. */
|
|
40
|
+
export interface InteractiveDocumentOptions extends HtmlDocumentOptions {
|
|
41
|
+
/** Per-instance opaque token required on every postMessage between iframe and host. */
|
|
42
|
+
readonly token: string;
|
|
43
|
+
}
|
|
44
|
+
/** Measure exact UTF-8 byte length without requiring Node's `Buffer` or a global `TextEncoder`. */
|
|
45
|
+
export declare function utf8ByteLength(text: string): number;
|
|
46
|
+
/** Escape text for safe inclusion inside HTML text nodes or double-quoted attributes. */
|
|
47
|
+
export declare function escapeHtml(value: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Validate whether an authored URL is safe for the given HTML attribute in static mode.
|
|
50
|
+
*
|
|
51
|
+
* @param attr - lowercased attribute name.
|
|
52
|
+
* @param value - raw attribute value.
|
|
53
|
+
* @param allowExternalResources - whether external `http(s):` media URLs are permitted.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isSafeStaticUrl(attr: string, value: string, allowExternalResources: boolean): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Sanitize CSS text (inline `style` attributes or `<style>` block bodies) by removing
|
|
58
|
+
* `@import`, legacy script expressions, and unsafe `url(...)` references.
|
|
59
|
+
*/
|
|
60
|
+
export declare function sanitizeCss(css: string, allowExternalResources: boolean): string;
|
|
61
|
+
/**
|
|
62
|
+
* Sanitize raw HTML markup for static, script-free preview rendering.
|
|
63
|
+
*
|
|
64
|
+
* Strips dangerous container tags, void metadata tags, inline event handlers,
|
|
65
|
+
* unsafe URL schemes, declarative shadow roots, and unsafe CSS expressions.
|
|
66
|
+
*/
|
|
67
|
+
export declare function sanitizeStaticHtml(rawHtml: string, allowExternalResources?: boolean): string;
|
|
68
|
+
/** Build the strict Content-Security-Policy string for static or interactive HTML sandboxes. */
|
|
69
|
+
export declare function buildSandboxCsp(mode: 'static' | 'interactive', allowExternalResources: boolean, staticNonce?: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Build a complete static HTML document ready for a sandboxed iframe.
|
|
72
|
+
*
|
|
73
|
+
* When `options.staticBridge` is omitted, CSP sets `script-src 'none'` for a
|
|
74
|
+
* zero-script `<iframe sandbox="">`. When `options.staticBridge` is provided,
|
|
75
|
+
* CSP locks script execution exclusively to `script-src 'nonce-<nonce>'` so
|
|
76
|
+
* only the host's own height/theme bridge runs while all author scripts stay
|
|
77
|
+
* stripped and CSP-blocked.
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildStaticHtmlDocument(rawHtml: string, options: HtmlDocumentOptions): string;
|
|
80
|
+
/**
|
|
81
|
+
* Build a complete interactive HTML document ready for a Blob URL inside
|
|
82
|
+
* `<iframe sandbox="allow-scripts">` (opaque origin, no `allow-same-origin`).
|
|
83
|
+
*
|
|
84
|
+
* Strips `<base>` and `<meta http-equiv="refresh"|"content-security-policy">`
|
|
85
|
+
* tags before prepending the renderer's own CSP and lightweight resize/theme bridge.
|
|
86
|
+
*/
|
|
87
|
+
export declare function buildInteractiveHtmlDocument(rawHtml: string, options: InteractiveDocumentOptions): string;
|
|
88
|
+
/**
|
|
89
|
+
* Prepare standalone SVG markup for safe rendering inside `<img src="blob:...">`.
|
|
90
|
+
*
|
|
91
|
+
* Ensures the SVG namespace (`xmlns="http://www.w3.org/2000/svg"`) is declared
|
|
92
|
+
* (browsers render blank `<img>` boxes when standalone SVG omits it) and strips
|
|
93
|
+
* scripts, SMIL animations, foreignObject, and inline event handlers.
|
|
94
|
+
*
|
|
95
|
+
* @returns normalized SVG string, or `null` when the input contains no `<svg>` root.
|
|
96
|
+
*/
|
|
97
|
+
export declare function prepareSvgForImage(rawSvg: string): string | null;
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Custom renderer",
|
|
4
|
+
"description": "First-class render_artifact streaming cards outside process folding, bundled visual-artifact skill, persistent Sidebar recovery, sandboxed HTML/SVG previews, and inline visual media fallback for DeepSeek Harness."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aqian0/dsh-renderer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Custom renderer plugin for DeepSeek Harness",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"deepseek-harness",
|
|
7
|
+
"dsh",
|
|
8
|
+
"renderer"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/AQian0/dsh-renderer#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/AQian0/dsh-renderer/issues"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/AQian0/dsh-renderer.git"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib/**/*.js",
|
|
21
|
+
"lib/types/**/*.d.ts",
|
|
22
|
+
"cordis.patch.yml",
|
|
23
|
+
"locale/*.json",
|
|
24
|
+
"icon.svg"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "lib/index.js",
|
|
28
|
+
"types": "lib/types/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./lib/types/index.d.ts",
|
|
32
|
+
"default": "./lib/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./config": {
|
|
35
|
+
"types": "./lib/types/config.d.ts",
|
|
36
|
+
"default": "./lib/config.js"
|
|
37
|
+
},
|
|
38
|
+
"./client": {
|
|
39
|
+
"types": "./lib/types/client.d.ts",
|
|
40
|
+
"default": "./lib/client.js"
|
|
41
|
+
},
|
|
42
|
+
"./locale/*.json": "./locale/*.json",
|
|
43
|
+
"./icon": "./icon.svg",
|
|
44
|
+
"./package.json": "./package.json",
|
|
45
|
+
"./cordis.patch.yml": "./cordis.patch.yml"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json && vp build --config vite.client.config.ts",
|
|
52
|
+
"prepack": "vp run build",
|
|
53
|
+
"format": "vp fmt",
|
|
54
|
+
"format:check": "vp fmt --check",
|
|
55
|
+
"lint": "vp lint",
|
|
56
|
+
"lint:fix": "vp lint --fix",
|
|
57
|
+
"check": "vp check --deny-warnings",
|
|
58
|
+
"check:fix": "vp check --fix",
|
|
59
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
60
|
+
"test:unit": "vp test",
|
|
61
|
+
"test:coverage": "vp test --coverage",
|
|
62
|
+
"test": "vp run check && vp run typecheck && vp test"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@shikijs/core": "^4.6.0",
|
|
66
|
+
"@shikijs/engine-javascript": "^4.6.0",
|
|
67
|
+
"@shikijs/langs": "^4.6.0",
|
|
68
|
+
"@types/node": "26.6.11",
|
|
69
|
+
"@vitest/coverage-v8": "5.1.1",
|
|
70
|
+
"typescript": "7.0.2",
|
|
71
|
+
"vite-plus": "1.8.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
75
|
+
"@deepseek-ai/schemastery": "^3.19.0"
|
|
76
|
+
},
|
|
77
|
+
"packageManager": "pnpm@12.23.0",
|
|
78
|
+
"dsh": {
|
|
79
|
+
"bundle": {
|
|
80
|
+
"patch": "./cordis.patch.yml"
|
|
81
|
+
},
|
|
82
|
+
"client": {
|
|
83
|
+
"platform": "web",
|
|
84
|
+
"inject": [
|
|
85
|
+
"@deepseek-ai/dsh-api-remotes",
|
|
86
|
+
"@deepseek-ai/dsh-client-locale",
|
|
87
|
+
"@deepseek-ai/dsh-client-resources",
|
|
88
|
+
"@deepseek-ai/dsh-client-ui-chat",
|
|
89
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
90
|
+
"@deepseek-ai/dsh-client-ui-session",
|
|
91
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
92
|
+
"@deepseek-ai/dsh-client-ui-theme",
|
|
93
|
+
"@deepseek-ai/dsh-client-ui-tool"
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|