@aqian0/dsh-renderer 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 +21 -0
- package/README.md +119 -2
- package/cordis.patch.yml +4 -0
- package/icon.svg +5 -0
- package/lib/client.js +738 -0
- package/lib/config.js +92 -0
- package/lib/host/artifact-tool.js +141 -0
- package/lib/host/media-bridge.js +102 -0
- package/lib/index.js +101 -0
- package/lib/shared/config-defaults.js +88 -0
- package/lib/shared/content-complexity.js +748 -0
- package/lib/shared/media-extractor.js +154 -0
- package/lib/shared/sandbox-core.js +217 -0
- package/lib/shared/sanitize.js +539 -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 +54 -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 +181 -0
- package/lib/types/client/workbench.d.ts +24 -0
- package/lib/types/client.d.ts +10 -0
- package/lib/types/config.d.ts +48 -0
- package/lib/types/host/artifact-tool.d.ts +53 -0
- package/lib/types/host/media-bridge.d.ts +47 -0
- package/lib/types/index.d.ts +29 -0
- package/lib/types/shared/config-defaults.d.ts +54 -0
- package/lib/types/shared/content-complexity.d.ts +88 -0
- package/lib/types/shared/media-extractor.d.ts +42 -0
- package/lib/types/shared/sandbox-core.d.ts +101 -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 +91 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal stroke-based 14px SVG icons matching DSH's compact action buttons.
|
|
3
|
+
*
|
|
4
|
+
* @module dsh-renderer/client/icons
|
|
5
|
+
*/
|
|
6
|
+
import type { ReactRuntime } from './types.ts';
|
|
7
|
+
/** Supported icon names rendered inside toolbar, document cards, and floating controls. */
|
|
8
|
+
export type IconName = 'sidebar' | 'expand' | 'download' | 'close' | 'zoomIn' | 'zoomOut' | 'grid' | 'copy' | 'check' | 'wrap' | 'htmlDoc' | 'svgDoc' | 'codeDoc' | 'textDoc' | 'chevronRight';
|
|
9
|
+
/** Render a crisp 14x14 outline icon inheriting `currentColor`. */
|
|
10
|
+
export declare function renderIcon(React: ReactRuntime, name: IconName, size?: number): unknown;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side localization dictionaries (`dshRenderer` namespace).
|
|
3
|
+
*
|
|
4
|
+
* Both `zh` and `en` MUST carry the exact same set of keys (`test/build.test.ts` enforces this).
|
|
5
|
+
*
|
|
6
|
+
* @module dsh-renderer/client/locales
|
|
7
|
+
*/
|
|
8
|
+
/** Client locale namespace registered with `ctx.locale`. */
|
|
9
|
+
export declare const LOCALE_NAMESPACE = "dshRenderer";
|
|
10
|
+
/** Complete English baseline dictionary. */
|
|
11
|
+
export declare const EN_DICT: {
|
|
12
|
+
readonly title: 'Custom renderer';
|
|
13
|
+
readonly preview: 'Preview';
|
|
14
|
+
readonly code: 'Code';
|
|
15
|
+
readonly copy: 'Copy code';
|
|
16
|
+
readonly copied: 'Copied';
|
|
17
|
+
readonly wrap: 'Toggle word wrap';
|
|
18
|
+
readonly openWorkbench: 'Workbench';
|
|
19
|
+
readonly fullscreen: 'Fullscreen';
|
|
20
|
+
readonly close: 'Close';
|
|
21
|
+
readonly download: 'Download';
|
|
22
|
+
readonly zoomIn: 'Zoom in';
|
|
23
|
+
readonly zoomOut: 'Zoom out';
|
|
24
|
+
readonly zoomFit: 'Fit';
|
|
25
|
+
readonly checkerboard: 'Grid background';
|
|
26
|
+
readonly sleepingNotice: 'HTML sandbox paused to save memory.';
|
|
27
|
+
readonly wakeUp: 'Resume preview';
|
|
28
|
+
readonly oversizeNotice: 'Preview skipped: content exceeds the configured byte limit.';
|
|
29
|
+
readonly invalidSvg: 'Unable to render SVG markup; showing source code.';
|
|
30
|
+
readonly runtimeError: 'Sandbox script error';
|
|
31
|
+
readonly sandboxFrameTitle: 'Sandboxed HTML preview';
|
|
32
|
+
readonly svgPreviewAlt: 'Rendered SVG preview';
|
|
33
|
+
readonly artifactMissing: 'This preview artifact is no longer available in memory.';
|
|
34
|
+
readonly artifactTabTitle: 'Preview';
|
|
35
|
+
readonly htmlDocument: 'HTML Document';
|
|
36
|
+
readonly svgDocument: 'SVG Graphic';
|
|
37
|
+
readonly markdownDocument: 'Markdown Document';
|
|
38
|
+
readonly codeDocument: '{lang} Document';
|
|
39
|
+
readonly generatingDocument: 'Generating document…';
|
|
40
|
+
readonly openDocumentNamed: 'Open document in sidebar: {title}';
|
|
41
|
+
readonly docMeta: '{type} · {lines} lines · {size}';
|
|
42
|
+
readonly docStreamingMeta: '{type} · Generating… · {lines} lines · {size}';
|
|
43
|
+
readonly docStreamingSizeMeta: '{type} · Generating… · {size}';
|
|
44
|
+
readonly docStreamingBareMeta: '{type} · Generating…';
|
|
45
|
+
readonly artifactError: 'Failed to render document';
|
|
46
|
+
readonly turnMediaHeading: 'Inline visual media';
|
|
47
|
+
readonly openImage: 'Inspect image';
|
|
48
|
+
};
|
|
49
|
+
/** Exact locale key union derived from {@link EN_DICT}. */
|
|
50
|
+
export type LocaleKey = keyof typeof EN_DICT;
|
|
51
|
+
/** Complete Chinese dictionary with identical keys to {@link EN_DICT}. */
|
|
52
|
+
export declare const ZH_DICT: Record<LocaleKey, string>;
|
|
53
|
+
/** Registered dictionary bundle handed to `ctx.locale.register`. */
|
|
54
|
+
export declare const DICTIONARIES: Record<'zh' | 'en', Record<LocaleKey, string>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive HTML sandbox iframe component (`Blob URL` + `sandbox="allow-scripts"`).
|
|
3
|
+
*
|
|
4
|
+
* Runs HTML previews directly in an opaque-origin iframe (never `allow-same-origin`),
|
|
5
|
+
* managed by {@link SandboxLruPool}, with token-verified `postMessage` auto-height,
|
|
6
|
+
* runtime error reporting, and live host theme synchronization.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-renderer/client/sandbox
|
|
9
|
+
*/
|
|
10
|
+
import type { ClientEnv } from './types.ts';
|
|
11
|
+
/** Props accepted by the HTML sandbox component. */
|
|
12
|
+
export interface HtmlSandboxProps {
|
|
13
|
+
readonly sandboxId: string;
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly maxHeight: number;
|
|
16
|
+
readonly fillHeight?: boolean | undefined;
|
|
17
|
+
readonly visible?: boolean | undefined;
|
|
18
|
+
readonly onRuntimeError?: ((message: string | null) => void) | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Trigger a client-side file download for one HTML or SVG artifact. */
|
|
21
|
+
export declare function downloadTextFile(filename: string, content: string, mimeType: string): void;
|
|
22
|
+
/** Create the React component rendering interactive sandboxed HTML. */
|
|
23
|
+
export declare function createHtmlSandboxComponent(env: ClientEnv): (props: HtmlSandboxProps) => unknown;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scoped stylesheet aligned with DSH's native design system (`--dsw-alias-*`,
|
|
3
|
+
* `--dsw-radius-*`, `--dsw-font-family`, `--ds-font-family-code`).
|
|
4
|
+
*
|
|
5
|
+
* Visual rules matched to DSH's native `.md-code-block` and document preview:
|
|
6
|
+
* - Outer card uses `--dsw-radius-lg` (16px), `--dsw-alias-markdown-code-block`,
|
|
7
|
+
* and crisp `0.5px` `--dsw-alias-border-l2` hairlines.
|
|
8
|
+
* - Header matches native code-block banner height, typography, and padding.
|
|
9
|
+
* - Segmented Preview/Code toggle uses DSH's dedicated
|
|
10
|
+
* `--dsw-alias-markdown-code-segment-*` tokens.
|
|
11
|
+
* - Toolbar actions are borderless ghost icon buttons + soft blue tinted pill
|
|
12
|
+
* for interactive mode (no heavy black borders or box-inside-box clutter).
|
|
13
|
+
* - SVG zoom controls float cleanly in a compact pill matching `ImageBody`.
|
|
14
|
+
* - Fence root sets `margin: 0` so Chat's block container owns spacing.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-renderer/client/styles
|
|
17
|
+
*/
|
|
18
|
+
export declare const RENDERER_STYLES = "\n.dshr-card {\n margin: 0;\n border-radius: var(--dsw-radius-lg, 16px);\n border: 0.5px solid var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.1));\n background: var(--dsw-alias-markdown-code-block, #f9fafb);\n color: var(--dsw-alias-label-primary, inherit);\n font-family: var(--dsw-font-family, system-ui, -apple-system, sans-serif);\n font-size: 13px;\n line-height: 1.5;\n overflow: hidden;\n}\n\n.dshr-toolbar {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n height: 40px;\n padding: 0 10px 0 16px;\n background: var(--dsw-alias-markdown-code-block-banner, var(--dsw-alias-markdown-code-block, #f9fafb));\n border-bottom: 0.5px solid var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.04));\n flex-wrap: nowrap;\n}\n\n.dshr-toolbar-group {\n display: inline-flex;\n align-items: center;\n gap: 8px;\n min-width: 0;\n}\n\n.dshr-actions {\n display: inline-flex;\n align-items: center;\n gap: 2px;\n flex: none;\n}\n\n.dshr-lang {\n font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Menlo, monospace);\n font-size: 12px;\n line-height: 18px;\n font-weight: 500;\n color: var(--dsw-alias-label-tertiary, #81858c);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n max-width: 240px;\n}\n\n.dshr-seg {\n display: inline-flex;\n align-items: center;\n gap: 2px;\n padding: 2px;\n border-radius: var(--dsw-radius-sm, 8px);\n background: var(--dsw-alias-markdown-code-segment-unselected, rgba(38, 49, 72, 0.06));\n}\n\n.dshr-seg-btn {\n appearance: none;\n border: 0;\n background: transparent;\n color: var(--dsw-alias-label-secondary, #61666b);\n padding: 2px 9px;\n border-radius: 6px;\n font-family: inherit;\n font-size: 12px;\n line-height: 18px;\n font-weight: 500;\n cursor: pointer;\n transition: background-color 0.14s ease, color 0.14s ease;\n}\n\n.dshr-seg-btn:hover:not([data-active=\"true\"]) {\n color: var(--dsw-alias-label-primary, inherit);\n}\n\n.dshr-seg-btn[data-active=\"true\"] {\n background: var(--dsw-alias-markdown-code-segment-selected, #ffffff);\n color: var(--dsw-alias-label-primary, inherit);\n box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);\n}\n\n.dshr-icon-btn {\n appearance: none;\n border: 0;\n background: transparent;\n color: var(--dsw-alias-label-secondary, #61666b);\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n padding: 0;\n border-radius: var(--dsw-radius-sm, 8px);\n cursor: pointer;\n transition: background-color 0.14s ease, color 0.14s ease;\n}\n\n.dshr-icon-btn:hover {\n background: var(--dsw-alias-interactive-bg-hover, rgba(38, 49, 72, 0.06));\n color: var(--dsw-alias-label-primary, inherit);\n}\n\n.dshr-icon-btn[aria-pressed=\"true\"] {\n background: var(--dsw-alias-interactive-bg-active, rgba(38, 49, 72, 0.1));\n color: var(--dsw-alias-label-primary, inherit);\n}\n\n.dshr-btn {\n appearance: none;\n border: 0.5px solid var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.1));\n background: var(--dsw-alias-button-floating-fill, var(--dsw-alias-bg-base, #ffffff));\n color: var(--dsw-alias-label-primary, inherit);\n padding: 5px 12px;\n border-radius: var(--dsw-radius-sm, 8px);\n font-family: inherit;\n font-size: 12px;\n line-height: 16px;\n font-weight: 500;\n cursor: pointer;\n transition: background-color 0.14s ease;\n}\n\n.dshr-btn:hover {\n background: var(--dsw-alias-button-floating-hover, var(--dsw-alias-interactive-bg-hover));\n}\n\n.dshr-btn-accent {\n border-color: transparent;\n background: var(--dsw-alias-state-business-tertiary, #e4edfd);\n color: var(--dsw-alias-state-business-primary, #4176e6);\n}\n\n.dshr-btn-accent:hover {\n background: var(--dsw-alias-state-business-tertiary, #e4edfd);\n opacity: 0.88;\n}\n\n.dshr-body {\n position: relative;\n background: var(--dsw-alias-bg-base, #ffffff);\n}\n\n.dshr-code-wrap {\n background: var(--dsw-alias-markdown-code-block, #f9fafb);\n}\n\n.dshr-code-wrap > * {\n margin: 0 !important;\n border: none !important;\n border-radius: 0 !important;\n box-shadow: none !important;\n}\n\n.dshr-code-scroll {\n overflow: auto;\n background: var(--shiki-background, var(--dsw-alias-markdown-code-block, #f9fafb));\n}\n\n.dshr-code-pre {\n margin: 0 !important;\n padding: 14px 16px;\n font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Menlo, monospace);\n font-size: 12.5px;\n line-height: 1.6;\n color: var(--shiki-foreground, var(--dsw-alias-label-primary, inherit));\n background: transparent;\n overflow: visible;\n white-space: pre;\n word-break: normal;\n overflow-wrap: normal;\n tab-size: 2;\n}\n\n.dshr-code-scroll[data-wrap=\"true\"] .dshr-code-pre {\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n}\n\n.dshr-code-inner {\n font-family: inherit;\n font-size: inherit;\n line-height: inherit;\n background: transparent !important;\n border: none !important;\n padding: 0 !important;\n}\n\n.dshr-frame-host {\n position: relative;\n width: 100%;\n background: var(--dsw-alias-bg-base, #ffffff);\n overflow: hidden;\n contain: layout style;\n}\n\n.dshr-iframe {\n display: block;\n width: 100%;\n height: 100%;\n border: none;\n background: var(--dsw-alias-bg-base, #ffffff);\n}\n\n.dshr-notice {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n padding: 8px 14px;\n font-size: 12px;\n color: var(--dsw-alias-label-secondary, #61666b);\n background: var(--dsw-alias-markdown-code-block, #f9fafb);\n border-bottom: 0.5px solid var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.04));\n}\n\n.dshr-error {\n padding: 8px 14px;\n font-size: 12px;\n color: var(--dsw-alias-state-error-primary, #ec1313);\n background: var(--dsw-alias-interactive-bg-hover-danger, rgba(236, 19, 19, 0.05));\n border-top: 0.5px solid var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.06));\n overflow-wrap: anywhere;\n}\n\n.dshr-sleeping {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 10px;\n padding: 28px 16px;\n color: var(--dsw-alias-label-secondary, #61666b);\n text-align: center;\n}\n\n.dshr-svg-wrap {\n position: relative;\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n min-height: 0;\n background: var(--dsw-alias-bg-base, #ffffff);\n}\n\n.dshr-svg-stage {\n overflow: auto;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 20px 16px 42px;\n min-height: 120px;\n}\n\n.dshr-svg-stage[data-checker=\"true\"] {\n background-image:\n linear-gradient(45deg, var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.05)) 25%, transparent 25%),\n linear-gradient(-45deg, var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.05)) 25%, transparent 25%),\n linear-gradient(45deg, transparent 75%, var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.05)) 75%),\n linear-gradient(-45deg, transparent 75%, var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.05)) 75%);\n background-size: 16px 16px;\n background-position: 0 0, 0 8px, 8px -8px, -8px 0;\n}\n\n.dshr-svg-img {\n display: block;\n max-width: 100%;\n height: auto;\n border-radius: var(--dsw-radius-xs, 4px);\n user-select: none;\n}\n\n.dshr-svg-floating {\n position: absolute;\n right: 10px;\n bottom: 10px;\n display: inline-flex;\n align-items: center;\n gap: 2px;\n padding: 3px;\n border-radius: var(--dsw-radius-sm, 8px);\n border: 0.5px solid var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.1));\n background: var(--dsw-alias-button-floating-fill, var(--dsw-alias-bg-base, #ffffff));\n box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);\n}\n\n.dshr-svg-divider {\n width: 1px;\n height: 14px;\n margin: 0 2px;\n background: var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.1));\n}\n\n.dshr-zoom-readout {\n appearance: none;\n border: 0;\n background: transparent;\n color: var(--dsw-alias-label-secondary, #61666b);\n min-width: 42px;\n height: 24px;\n padding: 0 6px;\n border-radius: 6px;\n font-family: inherit;\n font-size: 11px;\n line-height: 24px;\n text-align: center;\n cursor: pointer;\n transition: background-color 0.14s ease, color 0.14s ease;\n}\n\n.dshr-zoom-readout:hover {\n background: var(--dsw-alias-interactive-bg-hover, rgba(38, 49, 72, 0.06));\n color: var(--dsw-alias-label-primary, inherit);\n}\n\n.dshr-svg-floating .dshr-icon-btn {\n width: 24px;\n height: 24px;\n border-radius: 6px;\n}\n\n.dshr-workbench {\n display: flex;\n flex-direction: column;\n height: 100%;\n width: 100%;\n background: var(--dsw-alias-bg-base, #ffffff);\n color: var(--dsw-alias-label-primary, inherit);\n font-family: var(--dsw-font-family, system-ui, -apple-system, sans-serif);\n}\n\n.dshr-workbench-title {\n font-family: inherit;\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n color: var(--dsw-alias-label-primary, inherit);\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n max-width: 280px;\n}\n\n.dshr-tab-title-icon {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n color: var(--dsw-alias-state-business-primary, #4176e6);\n}\n\n.dshr-doc-card {\n appearance: none;\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: 10px;\n min-width: 0;\n width: 100%;\n min-height: 60px;\n padding: 8px 12px 8px 10px;\n margin: 0;\n overflow: hidden;\n border: 0.5px solid var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.06));\n border-radius: var(--dsw-radius-lg, 16px);\n background: var(--dsw-alias-card-fill, var(--dsw-alias-markdown-code-block, #f9fafb));\n color: var(--dsw-alias-label-primary, inherit);\n font-family: var(--dsw-font-family, system-ui, -apple-system, sans-serif);\n text-align: left;\n cursor: pointer;\n transition: background-color 120ms ease, border-color 120ms ease;\n}\n\n@media (hover: hover) {\n .dshr-doc-card[data-dshr-state=\"ready\"]:hover {\n background: var(--dsw-alias-card-fill-hover, var(--dsw-alias-interactive-bg-hover, rgba(38, 49, 72, 0.06)));\n border-color: var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.1));\n }\n\n .dshr-doc-card[data-dshr-state=\"ready\"]:hover .dshr-doc-chevron {\n color: var(--dsw-alias-label-primary, inherit);\n transform: translateX(2px);\n }\n}\n\n.dshr-doc-card:focus-visible {\n outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary, #4176e6));\n outline-offset: 2px;\n}\n\n.dshr-doc-icon {\n box-sizing: border-box;\n flex: none;\n display: grid;\n place-items: center;\n width: 40px;\n height: 40px;\n border: 0.5px solid var(--dsw-alias-border-l1, rgba(0, 0, 0, 0.06));\n border-radius: 10px;\n background: var(--dsw-alias-card-tile-fill, var(--dsw-alias-bg-base, #ffffff));\n color: var(--dsw-alias-state-business-primary, #4176e6);\n}\n\n.dshr-doc-details {\n display: flex;\n flex: 1;\n flex-direction: column;\n justify-content: center;\n gap: 2px;\n min-width: 0;\n}\n\n.dshr-doc-title {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n font-size: 13px;\n font-weight: 500;\n line-height: 20px;\n color: var(--dsw-alias-label-primary, inherit);\n}\n\n.dshr-doc-meta {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n font-size: 11px;\n font-weight: 400;\n line-height: 16px;\n color: var(--dsw-alias-label-tertiary, #81858c);\n}\n\n.dshr-doc-card[data-dshr-state=\"streaming\"],\n.dshr-doc-card[data-dshr-state=\"error\"] {\n cursor: default;\n}\n\n.dshr-doc-card[data-dshr-state=\"error\"] {\n border-color: var(--dsw-alias-state-error-primary, #ec1313);\n}\n\n.dshr-doc-card[data-dshr-state=\"error\"] .dshr-doc-icon,\n.dshr-doc-card[data-dshr-state=\"error\"] .dshr-doc-meta {\n color: var(--dsw-alias-state-error-primary, #ec1313);\n}\n\n@keyframes dshr-spin {\n to {\n transform: rotate(360deg);\n }\n}\n\n.dshr-spinner {\n box-sizing: border-box;\n width: 15px;\n height: 15px;\n flex: none;\n border-radius: 50%;\n border: 1.75px solid var(--dsw-alias-border-l3, rgba(0, 0, 0, 0.14));\n border-top-color: var(--dsw-alias-state-business-primary, #4176e6);\n animation: dshr-spin 0.8s linear infinite;\n}\n\n.dshr-doc-chevron {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n flex: none;\n color: var(--dsw-alias-label-tertiary, #81858c);\n transition: color 120ms ease, transform 120ms ease;\n}\n\n.dshr-workbench-body {\n flex: 1 1 auto;\n min-height: 0;\n overflow: auto;\n display: flex;\n flex-direction: column;\n background: var(--dsw-alias-bg-base, #ffffff);\n}\n\n.dshr-modal-backdrop {\n position: fixed;\n inset: 0;\n z-index: 1200;\n pointer-events: auto;\n background: var(--dsw-alias-bg-mask-1, rgba(0, 0, 0, 0.28));\n backdrop-filter: blur(4px);\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 24px;\n}\n\n.dshr-modal-panel {\n width: min(1120px, 94vw);\n height: min(820px, 90vh);\n border-radius: var(--dsw-radius-lg, 16px);\n overflow: hidden;\n border: 0.5px solid var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.12));\n background: var(--dsw-alias-bg-base, #ffffff);\n box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22);\n display: flex;\n flex-direction: column;\n}\n\n.dshr-turn-media {\n margin: 8px 0 0;\n padding: 10px 12px;\n border-radius: var(--dsw-radius-md, 12px);\n border: 0.5px solid var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.1));\n background: var(--dsw-alias-markdown-code-block, #f9fafb);\n font-family: var(--dsw-font-family, system-ui, -apple-system, sans-serif);\n}\n\n.dshr-turn-media-header {\n font-size: 11px;\n line-height: 16px;\n font-weight: 500;\n color: var(--dsw-alias-label-tertiary, #81858c);\n margin-bottom: 8px;\n}\n\n.dshr-turn-media-grid {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n}\n\n.dshr-turn-media-thumb {\n appearance: none;\n padding: 6px;\n border-radius: var(--dsw-radius-sm, 8px);\n border: 0.5px solid var(--dsw-alias-border-l2, rgba(0, 0, 0, 0.1));\n background: var(--dsw-alias-bg-base, #ffffff);\n cursor: pointer;\n display: inline-flex;\n flex-direction: column;\n align-items: center;\n gap: 5px;\n max-width: 220px;\n transition: border-color 0.14s ease, box-shadow 0.14s ease;\n}\n\n.dshr-turn-media-thumb:hover {\n border-color: var(--dsw-alias-state-business-primary, #4176e6);\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);\n}\n\n.dshr-turn-media-img {\n display: block;\n max-width: 208px;\n max-height: 150px;\n object-fit: contain;\n border-radius: var(--dsw-radius-xs, 4px);\n}\n\n.dshr-turn-media-caption {\n font-size: 11px;\n color: var(--dsw-alias-label-secondary, #61666b);\n max-width: 204px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.dshr-lightbox-img {\n display: block;\n max-width: 100%;\n max-height: 100%;\n margin: auto;\n object-fit: contain;\n border-radius: var(--dsw-radius-sm, 8px);\n}\n";
|
|
19
|
+
/** Insert the plugin stylesheet into `document.head` and return a cleanup callback. */
|
|
20
|
+
export declare function injectRendererStyles(): () => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe static SVG viewer rendered through an `<img>` Blob URL.
|
|
3
|
+
*
|
|
4
|
+
* Browsers strictly prohibit script execution and sub-resource fetches inside
|
|
5
|
+
* `<img src="blob:...">` SVG documents, matching DSH's `ImageBody` security model
|
|
6
|
+
* while preserving crisp vector scaling and floating zoom controls.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-renderer/client/svg-view
|
|
9
|
+
*/
|
|
10
|
+
import type { ClientEnv } from './types.ts';
|
|
11
|
+
/** Props accepted by the SVG viewer component. */
|
|
12
|
+
export interface SvgViewerProps {
|
|
13
|
+
readonly code: string;
|
|
14
|
+
readonly maxHeight: number;
|
|
15
|
+
readonly fillHeight?: boolean | undefined;
|
|
16
|
+
readonly onInvalid?: (() => void) | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Create the React component rendering sanitized SVG inside an `<img>` Blob URL. */
|
|
19
|
+
export declare function createSvgViewerComponent(env: ClientEnv): (props: SvgViewerProps) => unknown;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host theme token reader and `theme/change` subscription bridge for sandbox iframes.
|
|
3
|
+
*
|
|
4
|
+
* DSH defines `--dsw-alias-*` tokens on `body` and toggles dark mode through
|
|
5
|
+
* `body[data-ds-dark-theme]`. We sample `document.body` (falling back to
|
|
6
|
+
* `document.documentElement`) and watch both `theme/change` and body attributes
|
|
7
|
+
* so sandboxed iframes always stay synchronized with DSH's exact palette.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-renderer/client/theme
|
|
10
|
+
*/
|
|
11
|
+
import type { ClientContext, ClientThemeBridge } from './types.ts';
|
|
12
|
+
/**
|
|
13
|
+
* Create a live {@link ClientThemeBridge} tied to the plugin's Cordis lifecycle.
|
|
14
|
+
*
|
|
15
|
+
* Returns both the bridge and a `dispose` callback to register inside `ctx.effect`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createThemeBridge(ctx: ClientContext): {
|
|
18
|
+
readonly bridge: ClientThemeBridge;
|
|
19
|
+
readonly dispose: () => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-destructive `conversation.chat.turnTail` fallback rendering inline
|
|
3
|
+
* `data:image/*` URIs, raw `<img>` tags, and raw `<svg>` fragments emitted in
|
|
4
|
+
* Assistant prose outside code fences.
|
|
5
|
+
*
|
|
6
|
+
* @module dsh-renderer/client/turn-media
|
|
7
|
+
*/
|
|
8
|
+
import type { ClientEnv, TurnTailSlotProps } from './types.ts';
|
|
9
|
+
/** Create the React component registered into `conversation.chat.turnTail`. */
|
|
10
|
+
export declare function createTurnMediaComponent(env: ClientEnv): (props: TurnTailSlotProps) => unknown;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural browser runtime types for `@aqian0/dsh-renderer/client`.
|
|
3
|
+
*
|
|
4
|
+
* Keeps the client bundle free of `@types/react` and internal DSH UI package
|
|
5
|
+
* imports while maintaining strict TypeScript checking.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-renderer/client/types
|
|
8
|
+
*/
|
|
9
|
+
import type { RendererPluginConfig } from '../shared/config-defaults.ts';
|
|
10
|
+
import type { ArtifactKind, ArtifactStore, SandboxLruPool } from '../shared/sandbox-core.ts';
|
|
11
|
+
import type { SandboxThemeTokens } from '../shared/sanitize.ts';
|
|
12
|
+
import type { LocaleKey } from './locales.ts';
|
|
13
|
+
/** Minimal structural subset of React 18 provided by DSH's browser module table. */
|
|
14
|
+
export interface ReactRuntime {
|
|
15
|
+
readonly Fragment: unknown;
|
|
16
|
+
createElement(type: unknown, props?: Record<string, unknown> | null, ...children: unknown[]): unknown;
|
|
17
|
+
useState<T>(initial: T | (() => T)): [T, (next: T | ((prev: T) => T)) => void];
|
|
18
|
+
useEffect(effect: () => void | (() => void), deps?: readonly unknown[]): void;
|
|
19
|
+
useMemo<T>(factory: () => T, deps: readonly unknown[]): T;
|
|
20
|
+
useCallback<T extends (...args: never[]) => unknown>(fn: T, deps: readonly unknown[]): T;
|
|
21
|
+
useRef<T>(initial: T): {
|
|
22
|
+
current: T;
|
|
23
|
+
};
|
|
24
|
+
useSyncExternalStore?<T>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => T): T;
|
|
25
|
+
}
|
|
26
|
+
/** Structural subset of the browser Cordis `slots` service. */
|
|
27
|
+
export interface ClientSlotsService {
|
|
28
|
+
inject(name: string, callback: () => unknown): () => void;
|
|
29
|
+
register(definition: Record<string, unknown>, component: unknown): () => void;
|
|
30
|
+
}
|
|
31
|
+
/** Structural subset of the browser Cordis `locale` service. */
|
|
32
|
+
export interface ClientLocaleService {
|
|
33
|
+
register(namespace: string, dictionaries: Record<string, Record<string, string>>): () => void;
|
|
34
|
+
bind(namespace: string): (key: string, params?: Record<string, unknown>) => string;
|
|
35
|
+
}
|
|
36
|
+
/** Structural subset of the browser Cordis `theme` service. */
|
|
37
|
+
export interface ClientThemeService {
|
|
38
|
+
getTheme?(): {
|
|
39
|
+
readonly resolved?: string;
|
|
40
|
+
readonly mode?: string;
|
|
41
|
+
readonly id?: string;
|
|
42
|
+
} | undefined;
|
|
43
|
+
}
|
|
44
|
+
/** Structural subset of the optional right-Sidebar navigation service (`ctx.get('sidebarRight')`). */
|
|
45
|
+
export interface ClientSidebarRightService {
|
|
46
|
+
openResource(address: string, options?: Record<string, unknown>): void;
|
|
47
|
+
}
|
|
48
|
+
/** Structural subset of the optional right-Sidebar tab registry (`ctx.get('sidebarRightTabs')`). */
|
|
49
|
+
export interface ClientSidebarRightTabsService {
|
|
50
|
+
register(definition: {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly kind: string;
|
|
53
|
+
readonly patterns?: readonly string[];
|
|
54
|
+
readonly priority?: 'extension' | 'builtin' | 'fallback';
|
|
55
|
+
readonly title: (address: string) => string;
|
|
56
|
+
readonly keepMounted?: boolean;
|
|
57
|
+
}): () => void;
|
|
58
|
+
}
|
|
59
|
+
/** Structural view of the browser Cordis plugin context. */
|
|
60
|
+
export interface ClientContext {
|
|
61
|
+
readonly slots?: ClientSlotsService;
|
|
62
|
+
readonly locale?: ClientLocaleService;
|
|
63
|
+
get?(name: string): unknown;
|
|
64
|
+
inject?(deps: readonly string[], callback: (ctx: ClientContext) => void): unknown;
|
|
65
|
+
on?(event: string, listener: (...args: unknown[]) => void): () => void;
|
|
66
|
+
effect?(body: () => unknown, label?: string): () => void;
|
|
67
|
+
}
|
|
68
|
+
/** Owner + standard props passed to `conversation.chat.markdown.fence` HOC layers. */
|
|
69
|
+
export interface FenceSlotProps {
|
|
70
|
+
readonly lang: string;
|
|
71
|
+
readonly code: string;
|
|
72
|
+
readonly streaming: boolean;
|
|
73
|
+
readonly meta?: string | undefined;
|
|
74
|
+
readonly children?: unknown;
|
|
75
|
+
readonly sessionId?: string | undefined;
|
|
76
|
+
}
|
|
77
|
+
/** Owner + standard props passed to `conversation.chat.turnTail` list entries. */
|
|
78
|
+
export interface TurnTailSlotProps {
|
|
79
|
+
readonly turn?: {
|
|
80
|
+
readonly turn?: number;
|
|
81
|
+
readonly status?: string;
|
|
82
|
+
};
|
|
83
|
+
readonly seq?: number;
|
|
84
|
+
readonly sessionId?: string | undefined;
|
|
85
|
+
readonly useChat?: <T>(selector: (snapshot: ChatSnapshotLike) => T) => T;
|
|
86
|
+
}
|
|
87
|
+
/** Minimal Chat snapshot slice read by the `turnTail` media fallback. */
|
|
88
|
+
export interface ChatSnapshotLike {
|
|
89
|
+
readonly locations?: {
|
|
90
|
+
getTurn?(turn: number): readonly string[];
|
|
91
|
+
};
|
|
92
|
+
readonly nodes?: {
|
|
93
|
+
get?(key: string): ChatNodeLike | undefined;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Minimal Chat node shape inspected for settled Assistant text blocks. */
|
|
97
|
+
export interface ChatNodeLike {
|
|
98
|
+
readonly kind?: string;
|
|
99
|
+
readonly data?: {
|
|
100
|
+
readonly status?: string;
|
|
101
|
+
readonly blocks?: readonly {
|
|
102
|
+
readonly kind?: string;
|
|
103
|
+
readonly text?: string;
|
|
104
|
+
}[];
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Structural subset of DSH's `PartialArguments` lazy reader shared across tool phases. */
|
|
108
|
+
export interface PartialArgumentsLike {
|
|
109
|
+
has?(key: string): boolean;
|
|
110
|
+
complete?(key: string): boolean;
|
|
111
|
+
text?(key: string): string | undefined;
|
|
112
|
+
stringLength?(key: string, options?: {
|
|
113
|
+
readonly step?: number;
|
|
114
|
+
readonly offset?: number;
|
|
115
|
+
}): number | undefined;
|
|
116
|
+
}
|
|
117
|
+
/** Structural subset of `tool.call.toolview` owner + standard props across preparing/start/result. */
|
|
118
|
+
export interface ToolCallSlotProps {
|
|
119
|
+
readonly phase: 'preparing' | 'start' | 'result';
|
|
120
|
+
readonly callId: string;
|
|
121
|
+
readonly toolName: string;
|
|
122
|
+
readonly sessionId?: string | undefined;
|
|
123
|
+
readonly block: {
|
|
124
|
+
readonly callId?: string;
|
|
125
|
+
readonly kind?: string;
|
|
126
|
+
readonly name?: string;
|
|
127
|
+
readonly args?: PartialArgumentsLike;
|
|
128
|
+
readonly argsRaw?: string;
|
|
129
|
+
readonly call?: {
|
|
130
|
+
readonly name?: string;
|
|
131
|
+
readonly argsRaw?: string;
|
|
132
|
+
} | null;
|
|
133
|
+
readonly content?: readonly {
|
|
134
|
+
readonly type?: string;
|
|
135
|
+
readonly text?: string;
|
|
136
|
+
}[];
|
|
137
|
+
readonly isError?: boolean;
|
|
138
|
+
readonly error?: {
|
|
139
|
+
readonly name?: string;
|
|
140
|
+
readonly code?: string;
|
|
141
|
+
readonly reason?: string;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** Props passed to `sidebar.right.pane.tab` and `sidebar.right.pane.tab.title` keyed entries. */
|
|
146
|
+
export interface SidebarRightTabProps {
|
|
147
|
+
readonly useTabInfo?: () => {
|
|
148
|
+
readonly tab?: {
|
|
149
|
+
readonly id?: string;
|
|
150
|
+
readonly title?: string;
|
|
151
|
+
readonly contentId?: string;
|
|
152
|
+
readonly visible?: boolean;
|
|
153
|
+
readonly navigation?: {
|
|
154
|
+
readonly address?: string;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Theme observer facade shared across all Client components. */
|
|
160
|
+
export interface ClientThemeBridge {
|
|
161
|
+
getSnapshot(): SandboxThemeTokens;
|
|
162
|
+
subscribe(listener: () => void): () => void;
|
|
163
|
+
}
|
|
164
|
+
/** Shared client runtime environment passed into component factories. */
|
|
165
|
+
export interface ClientEnv {
|
|
166
|
+
readonly React: ReactRuntime;
|
|
167
|
+
readonly config: RendererPluginConfig;
|
|
168
|
+
readonly t: (key: LocaleKey, params?: Record<string, string | number>) => string;
|
|
169
|
+
readonly theme: ClientThemeBridge;
|
|
170
|
+
readonly sandboxPool: SandboxLruPool;
|
|
171
|
+
readonly artifacts: ArtifactStore;
|
|
172
|
+
readonly openArtifact: (input: {
|
|
173
|
+
readonly id?: string | undefined;
|
|
174
|
+
readonly kind: ArtifactKind;
|
|
175
|
+
readonly lang?: string | undefined;
|
|
176
|
+
readonly title: string;
|
|
177
|
+
readonly code: string;
|
|
178
|
+
readonly sessionId?: string | undefined;
|
|
179
|
+
readonly destination?: 'sidebar' | 'float' | 'modal';
|
|
180
|
+
}) => void;
|
|
181
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifact workbench rendered either in DSH's right Sidebar (`sidebar.right.pane.tab`)
|
|
3
|
+
* or inside a fullscreen overlay modal (`shell.overlay`) when the Sidebar service
|
|
4
|
+
* is unavailable or the user explicitly requests Fullscreen.
|
|
5
|
+
*
|
|
6
|
+
* Supports interactive HTML previews, zoomable SVG previews, and full-height
|
|
7
|
+
* Shiki-highlighted code/document artifacts.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-renderer/client/workbench
|
|
10
|
+
*/
|
|
11
|
+
import { type ArtifactRecord } from '../shared/sandbox-core.ts';
|
|
12
|
+
import { type IconName } from './icons.ts';
|
|
13
|
+
import type { ClientContext, ClientEnv } from './types.ts';
|
|
14
|
+
/** Stable tab implementation id registered in `sidebarRightTabs` and `sidebar.right.pane.tab`. */
|
|
15
|
+
export declare const WORKBENCH_TAB_ID = "@aqian0/dsh-renderer/workbench";
|
|
16
|
+
/** Tab kind claimed by `@aqian0/dsh-renderer` for `dsh-resource://dsh-renderer/artifact/**`. */
|
|
17
|
+
export declare const WORKBENCH_TAB_KIND = "dsh-renderer:artifact";
|
|
18
|
+
/** Choose the tab/document icon matching an artifact's kind and language. */
|
|
19
|
+
export declare function iconForArtifact(record: ArtifactRecord | undefined): IconName;
|
|
20
|
+
/**
|
|
21
|
+
* Register the right-Sidebar workbench tab (when `sidebarRightTabs` is available)
|
|
22
|
+
* and the `shell.overlay` fullscreen modal fallback.
|
|
23
|
+
*/
|
|
24
|
+
export declare function registerWorkbench(ctx: ClientContext, env: ClientEnv): () => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-renderer — browser half entry (bundled into a classic IIFE script).
|
|
3
|
+
*
|
|
4
|
+
* DSH serves third-party client plugins as classic scripts that register a lazy
|
|
5
|
+
* CommonJS factory through `window.__ModuleLoader__.load({ id, factory })`. The id
|
|
6
|
+
* must match this package's manifest name (`@aqian0/dsh-renderer`).
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-renderer/client
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin configuration schema and normalization helpers.
|
|
3
|
+
*
|
|
4
|
+
* @module dsh-renderer/config
|
|
5
|
+
*/
|
|
6
|
+
import z from '@deepseek-ai/schemastery';
|
|
7
|
+
import { DEFAULT_RENDERER_CONFIG, RENDERER_CONFIG_GLOBAL, SUPPORTED_FENCE_LANGUAGES, normalizeClientConfig, type DefaultViewMode, type FenceLanguage, type RendererPluginConfig } from './shared/config-defaults.ts';
|
|
8
|
+
export { DEFAULT_RENDERER_CONFIG, RENDERER_CONFIG_GLOBAL, SUPPORTED_FENCE_LANGUAGES, normalizeClientConfig };
|
|
9
|
+
export type { DefaultViewMode, FenceLanguage, RendererPluginConfig };
|
|
10
|
+
/** Configuration schema of the `renderer` bundle entry. */
|
|
11
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
12
|
+
enableFencePreview: z<boolean, boolean, "defined">;
|
|
13
|
+
fenceLanguages: z<("html" | "svg")[], ("html" | "svg")[], "defined">;
|
|
14
|
+
defaultView: z<"code" | "preview", "code" | "preview", "defined">;
|
|
15
|
+
allowExternalResources: z<boolean, boolean, "defined">;
|
|
16
|
+
enableWorkbench: z<boolean, boolean, "defined">;
|
|
17
|
+
complexContentToSidebar: z<boolean, boolean, "defined">;
|
|
18
|
+
enableArtifactTool: z<boolean, boolean, "defined">;
|
|
19
|
+
autoOpenArtifact: z<boolean, boolean, "defined">;
|
|
20
|
+
enableTurnMediaFallback: z<boolean, boolean, "defined">;
|
|
21
|
+
bridgeToolDataImages: z<boolean, boolean, "defined">;
|
|
22
|
+
maxContentBytes: z<number, number, "defined">;
|
|
23
|
+
inlineMaxHeight: z<number, number, "defined">;
|
|
24
|
+
maxActiveSandboxes: z<number, number, "defined">;
|
|
25
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
26
|
+
enableFencePreview: z<boolean, boolean, "defined">;
|
|
27
|
+
fenceLanguages: z<("html" | "svg")[], ("html" | "svg")[], "defined">;
|
|
28
|
+
defaultView: z<"code" | "preview", "code" | "preview", "defined">;
|
|
29
|
+
allowExternalResources: z<boolean, boolean, "defined">;
|
|
30
|
+
enableWorkbench: z<boolean, boolean, "defined">;
|
|
31
|
+
complexContentToSidebar: z<boolean, boolean, "defined">;
|
|
32
|
+
enableArtifactTool: z<boolean, boolean, "defined">;
|
|
33
|
+
autoOpenArtifact: z<boolean, boolean, "defined">;
|
|
34
|
+
enableTurnMediaFallback: z<boolean, boolean, "defined">;
|
|
35
|
+
bridgeToolDataImages: z<boolean, boolean, "defined">;
|
|
36
|
+
maxContentBytes: z<number, number, "defined">;
|
|
37
|
+
inlineMaxHeight: z<number, number, "defined">;
|
|
38
|
+
maxActiveSandboxes: z<number, number, "defined">;
|
|
39
|
+
}>>, "plain">;
|
|
40
|
+
/**
|
|
41
|
+
* Validate and normalize partial plugin configuration through {@link Config}.
|
|
42
|
+
*
|
|
43
|
+
* Deduplicates `fenceLanguages` while preserving declared order so downstream
|
|
44
|
+
* slot registrations never attempt duplicate keys.
|
|
45
|
+
*
|
|
46
|
+
* @param config - raw configuration object from Cordis.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveConfig(config?: Partial<RendererPluginConfig>): RendererPluginConfig;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-side `render_artifact` tool definition and system-prompt guidance.
|
|
3
|
+
*
|
|
4
|
+
* Allows the model to emit standalone interactive HTML pages, dense SVG
|
|
5
|
+
* diagrams, and long self-contained code/Markdown documents directly as
|
|
6
|
+
* streaming DSH Document Cards (rendered by `tool.call.toolview`) instead of
|
|
7
|
+
* flooding chat prose with hundreds of lines of raw code. Because tool calls
|
|
8
|
+
* are persisted in the DSH Session log, artifacts remain inspectable across
|
|
9
|
+
* reloads, forks, and replays.
|
|
10
|
+
*
|
|
11
|
+
* @module dsh-renderer/host/artifact-tool
|
|
12
|
+
*/
|
|
13
|
+
import { type ArtifactContentKind } from '../shared/content-complexity.ts';
|
|
14
|
+
/** Wire tool name shared by the Host tool registration and Client `tool.call.toolview`. */
|
|
15
|
+
export declare const ARTIFACT_TOOL_NAME = "render_artifact";
|
|
16
|
+
/** System-prompt section name registered on `ctx.systemPrompt`. */
|
|
17
|
+
export declare const ARTIFACT_PROMPT_SECTION_NAME = "dsh-renderer:artifact";
|
|
18
|
+
/** Canonical JSON value returned by `render_artifact`. */
|
|
19
|
+
export interface RenderArtifactOutput {
|
|
20
|
+
readonly artifactId: string;
|
|
21
|
+
readonly title: string;
|
|
22
|
+
readonly kind: ArtifactContentKind;
|
|
23
|
+
readonly lang: string;
|
|
24
|
+
readonly lines: number;
|
|
25
|
+
readonly bytes: number;
|
|
26
|
+
}
|
|
27
|
+
/** Structural subset of DSH's `ctx.tools` Host service. */
|
|
28
|
+
export interface HostToolsService {
|
|
29
|
+
register(definition: Record<string, unknown>): () => void;
|
|
30
|
+
}
|
|
31
|
+
/** Structural subset of DSH's `ctx.systemPrompt` Host service. */
|
|
32
|
+
export interface HostSystemPromptService {
|
|
33
|
+
section(section: {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly order: number;
|
|
36
|
+
readonly text: string;
|
|
37
|
+
}): () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a dependency-free DSH `ToolDefinition` object for `render_artifact`.
|
|
41
|
+
*
|
|
42
|
+
* Uses only the DSH-supported JSON Schema subset (`type`, `properties`, `required`,
|
|
43
|
+
* `additionalProperties`, `enum`, `description`).
|
|
44
|
+
*/
|
|
45
|
+
export declare function createRenderArtifactToolDefinition(options: {
|
|
46
|
+
readonly maxContentBytes: number;
|
|
47
|
+
}): Record<string, unknown>;
|
|
48
|
+
/** Concise system-prompt section steering the model to use `render_artifact` for heavy standalone output. */
|
|
49
|
+
export declare const ARTIFACT_PROMPT_SECTION: {
|
|
50
|
+
readonly name: "dsh-renderer:artifact";
|
|
51
|
+
readonly order: 2950;
|
|
52
|
+
readonly text: 'When the user asks for a standalone interactive HTML page/app, a detailed SVG diagram, or a long self-contained code/Markdown document to inspect rather than save to the workspace, call `render_artifact` instead of printing a large code fence in chat prose. Keep short snippets and inline explanations in regular Markdown.';
|
|
53
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional Host bridge converting `data:image/*` base64 payloads returned by
|
|
3
|
+
* third-party tools into durable DSH `ImageBlock` attachments via `ctx.attachments`.
|
|
4
|
+
*
|
|
5
|
+
* @module dsh-renderer/host/media-bridge
|
|
6
|
+
*/
|
|
7
|
+
/** Raster MIME types supported by DSH's `ctx.attachments.saveImage`. */
|
|
8
|
+
export type BridgeableImageMediaType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif';
|
|
9
|
+
/** Structural view of DSH's Host `attachments` service. */
|
|
10
|
+
export interface HostAttachmentsService {
|
|
11
|
+
readonly imageLimits?: {
|
|
12
|
+
readonly maxImageBytes?: number;
|
|
13
|
+
};
|
|
14
|
+
saveImage(input: {
|
|
15
|
+
readonly data: Uint8Array;
|
|
16
|
+
readonly mediaType: BridgeableImageMediaType;
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
}): Promise<unknown>;
|
|
19
|
+
}
|
|
20
|
+
/** Structural view of one ContentBlock inside a tool result. */
|
|
21
|
+
export interface ToolContentBlock {
|
|
22
|
+
readonly type: string;
|
|
23
|
+
readonly text?: string;
|
|
24
|
+
readonly [key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
/** Structural view of `tools/post-execute` result payload. */
|
|
27
|
+
export interface ToolExecutionOutcome {
|
|
28
|
+
readonly isError: boolean;
|
|
29
|
+
readonly content: readonly ToolContentBlock[];
|
|
30
|
+
}
|
|
31
|
+
/** Structural view of `tools/post-execute` decision return value. */
|
|
32
|
+
export interface PostToolAcceptDecision {
|
|
33
|
+
readonly kind: 'accept';
|
|
34
|
+
readonly content?: ToolContentBlock[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Scan a tool result's text blocks for base64 `data:image/*` payloads, persist them
|
|
38
|
+
* through `attachments.saveImage`, and append durable `{ type: 'image', attachment }`
|
|
39
|
+
* blocks so DSH's native `tool.call.images` gallery renders them.
|
|
40
|
+
*
|
|
41
|
+
* Returns `null` when no convertible image was found or saved.
|
|
42
|
+
*/
|
|
43
|
+
export declare function bridgeToolResultDataImages(toolName: string, result: ToolExecutionOutcome, attachments: HostAttachmentsService, options: {
|
|
44
|
+
readonly maxBytes: number;
|
|
45
|
+
readonly maxImages?: number;
|
|
46
|
+
readonly signal?: AbortSignal;
|
|
47
|
+
}): Promise<ToolContentBlock[] | null>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-renderer Host entry (`renderer` bundle row).
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities on the Host:
|
|
5
|
+
* 1. Validate and normalize plugin configuration through Schemastery.
|
|
6
|
+
* 2. Publish normalized configuration to the Web GUI via `webserver/index-inject`
|
|
7
|
+
* (`globalThis.__DSH_RENDERER_CONFIG__`) so the browser half stays in sync
|
|
8
|
+
* without duplicating configuration storage.
|
|
9
|
+
* 3. Optionally bridge base64 `data:image/*` payloads returned by third-party
|
|
10
|
+
* tools into durable DSH `ImageBlock` attachments when `bridgeToolDataImages`
|
|
11
|
+
* is enabled and `ctx.attachments` is mounted.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-renderer
|
|
14
|
+
*/
|
|
15
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
16
|
+
import { Config, DEFAULT_RENDERER_CONFIG, RENDERER_CONFIG_GLOBAL, SUPPORTED_FENCE_LANGUAGES, normalizeClientConfig, resolveConfig, type DefaultViewMode, type FenceLanguage, type RendererPluginConfig } from './config.ts';
|
|
17
|
+
/** Cordis plugin name. */
|
|
18
|
+
export declare const name = "renderer";
|
|
19
|
+
/** Host services required before {@link apply} runs (none: optional hooks bind lazily). */
|
|
20
|
+
export declare const inject: readonly [];
|
|
21
|
+
export { Config, DEFAULT_RENDERER_CONFIG, RENDERER_CONFIG_GLOBAL, SUPPORTED_FENCE_LANGUAGES, normalizeClientConfig, resolveConfig, };
|
|
22
|
+
export type { DefaultViewMode, FenceLanguage, RendererPluginConfig };
|
|
23
|
+
/**
|
|
24
|
+
* Activate the Host side of `@aqian0/dsh-renderer`.
|
|
25
|
+
*
|
|
26
|
+
* @param ctx - live Cordis context.
|
|
27
|
+
* @param config - partial plugin configuration.
|
|
28
|
+
*/
|
|
29
|
+
export declare function apply(ctx: Context, config?: Partial<RendererPluginConfig>): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency configuration types, defaults, and browser-safe normalizer.
|
|
3
|
+
*
|
|
4
|
+
* Kept separate from `src/config.ts` (which imports `@deepseek-ai/schemastery`)
|
|
5
|
+
* so the browser Client bundle stays 100% dependency-free.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-renderer/shared/config-defaults
|
|
8
|
+
*/
|
|
9
|
+
/** Supported Markdown fence languages rendered by Phase 1 of `@aqian0/dsh-renderer`. */
|
|
10
|
+
export declare const SUPPORTED_FENCE_LANGUAGES: readonly ['html', 'svg'];
|
|
11
|
+
/** Lowercased fence language key supported by the built-in fence renderers. */
|
|
12
|
+
export type FenceLanguage = (typeof SUPPORTED_FENCE_LANGUAGES)[number];
|
|
13
|
+
/** Initial presentation mode for a settled visual code fence. */
|
|
14
|
+
export type DefaultViewMode = 'preview' | 'code';
|
|
15
|
+
/** Global property name written by the Host `webserver/index-inject` hook and read by the Client. */
|
|
16
|
+
export declare const RENDERER_CONFIG_GLOBAL = "__DSH_RENDERER_CONFIG__";
|
|
17
|
+
/** Normalized plugin configuration shared by the Host and Client halves. */
|
|
18
|
+
export interface RendererPluginConfig {
|
|
19
|
+
/** Enable Markdown fence visualization layers in the Chat flow. */
|
|
20
|
+
readonly enableFencePreview: boolean;
|
|
21
|
+
/** Lowercased fence languages handled by the renderer. */
|
|
22
|
+
readonly fenceLanguages: readonly FenceLanguage[];
|
|
23
|
+
/** Initial tab shown for a settled visual fence (`preview` or `code`). */
|
|
24
|
+
readonly defaultView: DefaultViewMode;
|
|
25
|
+
/** Whether HTML sandboxes may fetch external HTTPS resources. */
|
|
26
|
+
readonly allowExternalResources: boolean;
|
|
27
|
+
/** Enable opening visual artifacts in the right Sidebar workbench (falls back to a modal). */
|
|
28
|
+
readonly enableWorkbench: boolean;
|
|
29
|
+
/** Collapse overly complex HTML, SVG, or code/document fences into a DSH Document Expand Card that opens in the right Sidebar. */
|
|
30
|
+
readonly complexContentToSidebar: boolean;
|
|
31
|
+
/** Register the `render_artifact` Host tool and prompt guidance so models emit standalone documents directly as streaming cards. */
|
|
32
|
+
readonly enableArtifactTool: boolean;
|
|
33
|
+
/** Automatically open settled `render_artifact` cards in the right Sidebar without waiting for a click. */
|
|
34
|
+
readonly autoOpenArtifact: boolean;
|
|
35
|
+
/** Enable the non-destructive `turnTail` fallback for raw HTML/SVG and `data:image/*` prose media. */
|
|
36
|
+
readonly enableTurnMediaFallback: boolean;
|
|
37
|
+
/** Convert `data:image/*` strings in tool results into durable DSH image attachments on the Host. */
|
|
38
|
+
readonly bridgeToolDataImages: boolean;
|
|
39
|
+
/** Maximum UTF-8 byte size accepted per visual fence or extracted media item. */
|
|
40
|
+
readonly maxContentBytes: number;
|
|
41
|
+
/** Maximum inline preview height in CSS pixels before scrolling or expanding. */
|
|
42
|
+
readonly inlineMaxHeight: number;
|
|
43
|
+
/** Maximum number of concurrently mounted interactive iframe sandboxes (LRU eviction). */
|
|
44
|
+
readonly maxActiveSandboxes: number;
|
|
45
|
+
}
|
|
46
|
+
/** Baseline defaults used when configuration fields or Host injections are absent. */
|
|
47
|
+
export declare const DEFAULT_RENDERER_CONFIG: RendererPluginConfig;
|
|
48
|
+
/**
|
|
49
|
+
* Safely coerce an untrusted global config payload (e.g. `globalThis.__DSH_RENDERER_CONFIG__`)
|
|
50
|
+
* into a complete {@link RendererPluginConfig} without requiring Schemastery in the browser bundle.
|
|
51
|
+
*
|
|
52
|
+
* @param raw - untrusted value read from the browser global object.
|
|
53
|
+
*/
|
|
54
|
+
export declare function normalizeClientConfig(raw: unknown): RendererPluginConfig;
|