@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,50 @@
|
|
|
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
|
+
enableArtifactSkill: z<boolean, boolean, "defined">;
|
|
20
|
+
autoOpenArtifact: z<boolean, boolean, "defined">;
|
|
21
|
+
enableTurnMediaFallback: z<boolean, boolean, "defined">;
|
|
22
|
+
bridgeToolDataImages: z<boolean, boolean, "defined">;
|
|
23
|
+
maxContentBytes: z<number, number, "defined">;
|
|
24
|
+
inlineMaxHeight: z<number, number, "defined">;
|
|
25
|
+
maxActiveSandboxes: z<number, number, "defined">;
|
|
26
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
27
|
+
enableFencePreview: z<boolean, boolean, "defined">;
|
|
28
|
+
fenceLanguages: z<("html" | "svg")[], ("html" | "svg")[], "defined">;
|
|
29
|
+
defaultView: z<"code" | "preview", "code" | "preview", "defined">;
|
|
30
|
+
allowExternalResources: z<boolean, boolean, "defined">;
|
|
31
|
+
enableWorkbench: z<boolean, boolean, "defined">;
|
|
32
|
+
complexContentToSidebar: z<boolean, boolean, "defined">;
|
|
33
|
+
enableArtifactTool: z<boolean, boolean, "defined">;
|
|
34
|
+
enableArtifactSkill: z<boolean, boolean, "defined">;
|
|
35
|
+
autoOpenArtifact: z<boolean, boolean, "defined">;
|
|
36
|
+
enableTurnMediaFallback: z<boolean, boolean, "defined">;
|
|
37
|
+
bridgeToolDataImages: z<boolean, boolean, "defined">;
|
|
38
|
+
maxContentBytes: z<number, number, "defined">;
|
|
39
|
+
inlineMaxHeight: z<number, number, "defined">;
|
|
40
|
+
maxActiveSandboxes: z<number, number, "defined">;
|
|
41
|
+
}>>, "plain">;
|
|
42
|
+
/**
|
|
43
|
+
* Validate and normalize partial plugin configuration through {@link Config}.
|
|
44
|
+
*
|
|
45
|
+
* Deduplicates `fenceLanguages` while preserving declared order so downstream
|
|
46
|
+
* slot registrations never attempt duplicate keys.
|
|
47
|
+
*
|
|
48
|
+
* @param config - raw configuration object from Cordis.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveConfig(config?: Partial<RendererPluginConfig>): RendererPluginConfig;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundled DSH runtime skill (`visual-artifact`) registered on `ctx.skills`.
|
|
3
|
+
*
|
|
4
|
+
* Keeps the always-on system prompt minimal while surfacing a clear, discoverable
|
|
5
|
+
* entry in DSH's `<available_skills>` catalog and enabling direct user invocation
|
|
6
|
+
* via `/visual-artifact`. When loaded on demand, it gives the model concrete craft
|
|
7
|
+
* rules for self-contained SVG diagrams, interactive HTML apps/charts, and long
|
|
8
|
+
* structured documents rendered through `render_artifact`.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-renderer/host/artifact-skill
|
|
11
|
+
*/
|
|
12
|
+
/** Kebab-case skill name registered with DSH's `ctx.skills` service. */
|
|
13
|
+
export declare const ARTIFACT_SKILL_NAME = "visual-artifact";
|
|
14
|
+
/** Structural subset of DSH's `ctx.skills` Host service (`@deepseek-ai/dsh-skill`). */
|
|
15
|
+
export interface HostSkillsService {
|
|
16
|
+
register(skill: {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly description: string;
|
|
19
|
+
readonly whenToUse?: string;
|
|
20
|
+
readonly source: string;
|
|
21
|
+
readonly content: string;
|
|
22
|
+
readonly invocation?: {
|
|
23
|
+
readonly modelInvocable: boolean;
|
|
24
|
+
readonly userInvocable: boolean;
|
|
25
|
+
};
|
|
26
|
+
}): () => void;
|
|
27
|
+
}
|
|
28
|
+
/** Bundled runtime skill registration accepted by DSH `ctx.skills.register`. */
|
|
29
|
+
export declare const ARTIFACT_SKILL_REGISTRATION: {
|
|
30
|
+
readonly name: "visual-artifact";
|
|
31
|
+
readonly description: 'Create visual diagrams (architecture, flow, sequence, ER), interactive HTML demos/charts/prototypes, or long standalone documents rendered directly in the conversation and right Sidebar via render_artifact.';
|
|
32
|
+
readonly whenToUse: 'Use when a diagram, chart, interactive visualization, UI prototype, or long standalone document communicates the answer better than plain text or ASCII art.';
|
|
33
|
+
readonly source: 'bundled';
|
|
34
|
+
readonly invocation: {
|
|
35
|
+
readonly modelInvocable: true;
|
|
36
|
+
readonly userInvocable: true;
|
|
37
|
+
};
|
|
38
|
+
readonly content: string;
|
|
39
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
/**
|
|
19
|
+
* Placement order immediately after DSH's `DELIVERABLE_FILE_REFERENCES` (9000)
|
|
20
|
+
* and before `STRUCTURED_OUTPUT` (9900) / `HARNESS_SOURCE` (10000), so artifact
|
|
21
|
+
* guidance is not overshadowed by workspace file-delivery rules while remaining
|
|
22
|
+
* inside the reusable KV-cache prompt prefix.
|
|
23
|
+
*/
|
|
24
|
+
export declare const ARTIFACT_PROMPT_ORDER = 9050;
|
|
25
|
+
/** Canonical JSON value returned by `render_artifact`. */
|
|
26
|
+
export interface RenderArtifactOutput {
|
|
27
|
+
readonly artifactId: string;
|
|
28
|
+
readonly title: string;
|
|
29
|
+
readonly kind: ArtifactContentKind;
|
|
30
|
+
readonly lang: string;
|
|
31
|
+
readonly lines: number;
|
|
32
|
+
readonly bytes: number;
|
|
33
|
+
}
|
|
34
|
+
/** Structural subset of DSH's `ctx.tools` Host service. */
|
|
35
|
+
export interface HostToolsService {
|
|
36
|
+
register(definition: Record<string, unknown>): () => void;
|
|
37
|
+
get?(name: string, scope?: unknown, toolSet?: unknown): unknown;
|
|
38
|
+
}
|
|
39
|
+
/** Structural subset of `AssembleContext` passed by DSH's `ctx.systemPrompt`. */
|
|
40
|
+
export interface HostPromptAssembleContext {
|
|
41
|
+
readonly scope?: unknown;
|
|
42
|
+
readonly toolSet?: unknown;
|
|
43
|
+
}
|
|
44
|
+
/** Structural subset of DSH's `ctx.systemPrompt` Host service. */
|
|
45
|
+
export interface HostSystemPromptService {
|
|
46
|
+
section(section: {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly order: number;
|
|
49
|
+
readonly text: string | ((context: HostPromptAssembleContext) => string);
|
|
50
|
+
readonly interpolate?: boolean;
|
|
51
|
+
}): () => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a dependency-free DSH `ToolDefinition` object for `render_artifact`.
|
|
55
|
+
*
|
|
56
|
+
* Uses only the DSH-supported JSON Schema subset (`type`, `properties`, `required`,
|
|
57
|
+
* `additionalProperties`, `enum`, `description`).
|
|
58
|
+
*/
|
|
59
|
+
export declare function createRenderArtifactToolDefinition(options: {
|
|
60
|
+
readonly maxContentBytes: number;
|
|
61
|
+
}): Record<string, unknown>;
|
|
62
|
+
/** Prompt guidance steering natural, intent-driven use of `render_artifact`. */
|
|
63
|
+
export declare const ARTIFACT_PROMPT_TEXT: string;
|
|
64
|
+
/** Static system-prompt section retained for callers and tests inspecting the constant directly. */
|
|
65
|
+
export declare const ARTIFACT_PROMPT_SECTION: {
|
|
66
|
+
readonly name: "dsh-renderer:artifact";
|
|
67
|
+
readonly order: 9050;
|
|
68
|
+
readonly text: string;
|
|
69
|
+
readonly interpolate: false;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Create a tool-aware system-prompt section for `render_artifact`.
|
|
73
|
+
*
|
|
74
|
+
* Omits guidance automatically when `render_artifact` is restricted or shadowed
|
|
75
|
+
* for the assembling agent scope (`ctx.tools.get(name, scope, toolSet)`).
|
|
76
|
+
*/
|
|
77
|
+
export declare function createArtifactPromptSection(getTools?: () => HostToolsService | undefined): {
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly order: number;
|
|
80
|
+
readonly text: (context: HostPromptAssembleContext) => string;
|
|
81
|
+
readonly interpolate: boolean;
|
|
82
|
+
};
|
|
@@ -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,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-dependency streaming JSON parser and durable event extractor for
|
|
3
|
+
* `render_artifact` tool calls.
|
|
4
|
+
*
|
|
5
|
+
* Shared by the Conversation node assembler (`artifact-node.ts`) and the
|
|
6
|
+
* `ctx.resources` session-history recovery provider (`artifact-resource.ts`).
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-renderer/shared/artifact-stream
|
|
9
|
+
*/
|
|
10
|
+
import { type ArtifactContentKind } from './content-complexity.ts';
|
|
11
|
+
/** Canonical tool name matching Host registration (`src/host/artifact-tool.ts`). */
|
|
12
|
+
export declare const RENDER_ARTIFACT_TOOL_NAME = "render_artifact";
|
|
13
|
+
/** Partially decoded top-level fields from a streaming JSON object prefix. */
|
|
14
|
+
export interface StreamingArtifactFields {
|
|
15
|
+
readonly title?: string | undefined;
|
|
16
|
+
readonly kind?: ArtifactContentKind | undefined;
|
|
17
|
+
readonly lang?: string | undefined;
|
|
18
|
+
readonly contentBytes?: number | undefined;
|
|
19
|
+
readonly contentLines?: number | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** Normalized complete `render_artifact` payload extracted from tool arguments. */
|
|
22
|
+
export interface ParsedArtifactArguments {
|
|
23
|
+
readonly artifactId: string;
|
|
24
|
+
readonly title: string;
|
|
25
|
+
readonly kind: ArtifactContentKind;
|
|
26
|
+
readonly lang: string;
|
|
27
|
+
readonly content: string;
|
|
28
|
+
readonly lines: number;
|
|
29
|
+
readonly bytes: number;
|
|
30
|
+
}
|
|
31
|
+
/** Logged `render_artifact` invocation extracted from a durable Session event. */
|
|
32
|
+
export interface LoggedRenderArtifact extends ParsedArtifactArguments {
|
|
33
|
+
readonly callId: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Incrementally extract top-level `title`, `kind`, `lang`, and streamed `content`
|
|
37
|
+
* size/line estimates from a partial JSON object produced by `tool-call-delta`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractStreamingArtifactFields(rawJsonPrefix: string): StreamingArtifactFields;
|
|
40
|
+
/**
|
|
41
|
+
* Parse and validate complete `render_artifact` arguments (either a JSON string
|
|
42
|
+
* from `tool/call` or a plain object from PTC `tool/ptc-dispatch*`).
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseArtifactToolArguments(raw: unknown): ParsedArtifactArguments | null;
|
|
45
|
+
/**
|
|
46
|
+
* Extract a complete logged `render_artifact` invocation from a durable DSH
|
|
47
|
+
* Session event (`tool/call`, `tool/ptc-dispatch-start`, or `tool/ptc-dispatch`).
|
|
48
|
+
*/
|
|
49
|
+
export declare function extractLoggedRenderArtifact(event: {
|
|
50
|
+
readonly type: string;
|
|
51
|
+
readonly data: unknown;
|
|
52
|
+
}): LoggedRenderArtifact | undefined;
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
/** Register the bundled `visual-artifact` DSH skill so agents load visual craft guidance on demand and users can invoke `/visual-artifact`. */
|
|
34
|
+
readonly enableArtifactSkill: boolean;
|
|
35
|
+
/** Automatically open newly completed live `render_artifact` results in the right Sidebar (historical replays stay click-to-open). */
|
|
36
|
+
readonly autoOpenArtifact: boolean;
|
|
37
|
+
/** Enable the non-destructive `turnTail` fallback for raw HTML/SVG and `data:image/*` prose media. */
|
|
38
|
+
readonly enableTurnMediaFallback: boolean;
|
|
39
|
+
/** Convert `data:image/*` strings in tool results into durable DSH image attachments on the Host. */
|
|
40
|
+
readonly bridgeToolDataImages: boolean;
|
|
41
|
+
/** Maximum UTF-8 byte size accepted per visual fence or extracted media item. */
|
|
42
|
+
readonly maxContentBytes: number;
|
|
43
|
+
/** Maximum inline preview height in CSS pixels before scrolling or expanding. */
|
|
44
|
+
readonly inlineMaxHeight: number;
|
|
45
|
+
/** Maximum number of concurrently mounted interactive iframe sandboxes (LRU eviction). */
|
|
46
|
+
readonly maxActiveSandboxes: number;
|
|
47
|
+
}
|
|
48
|
+
/** Baseline defaults used when configuration fields or Host injections are absent. */
|
|
49
|
+
export declare const DEFAULT_RENDERER_CONFIG: RendererPluginConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Safely coerce an untrusted global config payload (e.g. `globalThis.__DSH_RENDERER_CONFIG__`)
|
|
52
|
+
* into a complete {@link RendererPluginConfig} without requiring Schemastery in the browser bundle.
|
|
53
|
+
*
|
|
54
|
+
* @param raw - untrusted value read from the browser global object.
|
|
55
|
+
*/
|
|
56
|
+
export declare function normalizeClientConfig(raw: unknown): RendererPluginConfig;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure content complexity analysis, document title extraction, language labels,
|
|
3
|
+
* and deterministic artifact identity helpers across HTML, SVG, Markdown, data,
|
|
4
|
+
* and general code fences.
|
|
5
|
+
*
|
|
6
|
+
* Used to decide when a Markdown fence in the Chat flow is too complex or long
|
|
7
|
+
* for comfortable inline reading and should instead render as a DSH-styled
|
|
8
|
+
* Document Expand Card that opens in the right Sidebar workbench.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-renderer/shared/content-complexity
|
|
11
|
+
*/
|
|
12
|
+
/** Artifact presentation category used across the Chat card and Sidebar workbench. */
|
|
13
|
+
export type ArtifactContentKind = 'html' | 'svg' | 'code';
|
|
14
|
+
/** Broad document family used for complexity scoring and card iconography. */
|
|
15
|
+
export type ContentCategory = 'html' | 'svg' | 'markdown' | 'data' | 'diff' | 'code';
|
|
16
|
+
/** Individual heuristic signals contributing to complexity classification. */
|
|
17
|
+
export type ContentComplexityReason = 'meta-override' | 'large-size' | 'many-lines' | 'full-document' | 'substantial-script' | 'heavy-runtime-api' | 'external-assets' | 'substantial-style' | 'viewport-layout' | 'rich-dom' | 'app-landmarks' | 'interactive-graphics' | 'rich-vector' | 'text-heavy-diagram' | 'large-canvas' | 'vector-defs' | 'dense-code' | 'wide-lines' | 'structured-data' | 'multi-section-doc' | 'large-diff';
|
|
18
|
+
/** Measured metrics extracted from a fence body. */
|
|
19
|
+
export interface ContentComplexityMetrics {
|
|
20
|
+
readonly bytes: number;
|
|
21
|
+
readonly lines: number;
|
|
22
|
+
readonly maxLineLength: number;
|
|
23
|
+
readonly tagCount?: number | undefined;
|
|
24
|
+
readonly landmarkCount?: number | undefined;
|
|
25
|
+
readonly scriptChars?: number | undefined;
|
|
26
|
+
readonly styleChars?: number | undefined;
|
|
27
|
+
readonly primitiveCount?: number | undefined;
|
|
28
|
+
readonly textNodeCount?: number | undefined;
|
|
29
|
+
readonly symbolCount?: number | undefined;
|
|
30
|
+
readonly headingCount?: number | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Result of classifying whether a fence should collapse into a Sidebar document card. */
|
|
33
|
+
export interface ContentComplexityAnalysis {
|
|
34
|
+
readonly isComplex: boolean;
|
|
35
|
+
readonly category: ContentCategory;
|
|
36
|
+
readonly score: number;
|
|
37
|
+
readonly reasons: readonly ContentComplexityReason[];
|
|
38
|
+
readonly metrics: ContentComplexityMetrics;
|
|
39
|
+
}
|
|
40
|
+
/** Minimum composite score required to collapse a fence into a Sidebar document card. */
|
|
41
|
+
export declare const COMPLEX_CONTENT_SCORE_THRESHOLD = 6;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve whether a Markdown fence language + body should use a visual preview
|
|
44
|
+
* layer (`'html'` or `'svg'`), including `htm`/`xhtml`/`svg+xml` aliases and
|
|
45
|
+
* root-element `<svg>` sniffing inside `xml` fences.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveVisualFenceKind(lang: string, code: string): 'html' | 'svg' | null;
|
|
48
|
+
/** Classify a lowercased fence language (and optional body for XML `<svg>` sniffing) into a content category. */
|
|
49
|
+
export declare function classifyContentCategory(lang: string, code?: string): ContentCategory;
|
|
50
|
+
/** Return a clean human-facing label for a fence language identifier. */
|
|
51
|
+
export declare function formatFenceLanguageLabel(lang: string): string;
|
|
52
|
+
/** Return an appropriate download file extension for an artifact kind + language. */
|
|
53
|
+
export declare function fileExtensionForFence(kind: ArtifactContentKind, lang?: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Analyze an HTML snippet to determine whether it is complex enough to display
|
|
56
|
+
* as a compact Document Expand Card in the Chat flow instead of an inline iframe.
|
|
57
|
+
*/
|
|
58
|
+
export declare function analyzeHtmlComplexity(code: string, meta?: string): ContentComplexityAnalysis;
|
|
59
|
+
/**
|
|
60
|
+
* Analyze an SVG graphic to determine whether it is a large or dense diagram/illustration
|
|
61
|
+
* better inspected in the full-width right Sidebar workbench.
|
|
62
|
+
*/
|
|
63
|
+
export declare function analyzeSvgComplexity(code: string, meta?: string): ContentComplexityAnalysis;
|
|
64
|
+
/**
|
|
65
|
+
* Analyze a general code, Markdown, structured-data, or diff fence to decide
|
|
66
|
+
* whether it is overly long/complex for the Chat flow and should move to the Sidebar.
|
|
67
|
+
*/
|
|
68
|
+
export declare function analyzeCodeComplexity(lang: string, code: string, meta?: string): ContentComplexityAnalysis;
|
|
69
|
+
/** Unified complexity analyzer dispatching HTML, SVG, and general code/document fences. */
|
|
70
|
+
export declare function analyzeFenceComplexity(lang: string, code: string, meta?: string): ContentComplexityAnalysis;
|
|
71
|
+
/**
|
|
72
|
+
* Decide whether a still-streaming fence should collapse early into a "Generating…"
|
|
73
|
+
* Document Expand Card instead of flooding the Chat flow with hundreds of raw lines.
|
|
74
|
+
*
|
|
75
|
+
* Triggers immediately on explicit `sidebar`/`artifact`/`document` meta hints, full
|
|
76
|
+
* HTML document openings (`<!doctype html>` or `<html>` + `<head>`/`<style>`), large
|
|
77
|
+
* SVG canvases, or as soon as the partial body crosses the standard complexity threshold.
|
|
78
|
+
*/
|
|
79
|
+
export declare function shouldCollapseWhileStreaming(lang: string, code: string, meta?: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Derive a concise human-readable document title from fence metadata or content structure
|
|
82
|
+
* (`title`/`file`/`filename`/`path` meta, `<title>`, `<h1>`, Markdown `# Heading`, or
|
|
83
|
+
* leading path comment / primary symbol) before falling back to a localized default.
|
|
84
|
+
*/
|
|
85
|
+
export declare function deriveFenceDocumentTitle(lang: string, code: string, meta?: string, fallback?: string): string;
|
|
86
|
+
/** Format a UTF-8 byte count into a compact human-readable size label (e.g. `9.4 KB`). */
|
|
87
|
+
export declare function formatByteSize(bytes: number): string;
|
|
88
|
+
/**
|
|
89
|
+
* Compute a deterministic, collision-resistant artifact id from kind, language, and code.
|
|
90
|
+
*
|
|
91
|
+
* Ensures re-clicking the same document card focuses the existing right-Sidebar tab
|
|
92
|
+
* instead of spawning duplicates, and lets restored tabs reconnect across reloads.
|
|
93
|
+
*/
|
|
94
|
+
export declare function computeArtifactId(kind: ArtifactContentKind, code: string, lang?: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-destructive prose media extractor for the `conversation.chat.turnTail` fallback.
|
|
3
|
+
*
|
|
4
|
+
* DSH's built-in `MarkdownText` currently rejects `data:image/*` Markdown image
|
|
5
|
+
* destinations and renders raw HTML (`<img>`, `<svg>`) as literal escaped text.
|
|
6
|
+
* This module scans Assistant prose *outside* code fences and inline code spans
|
|
7
|
+
* to recover those visual items without duplicating fenced `html`/`svg` blocks.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-renderer/shared/media-extractor
|
|
10
|
+
*/
|
|
11
|
+
/** Extracted image or SVG item ready for fallback presentation in `turnTail`. */
|
|
12
|
+
export interface ExtractedMediaItem {
|
|
13
|
+
/** Stable deduplication key derived from item kind and normalized content. */
|
|
14
|
+
readonly key: string;
|
|
15
|
+
/** Media kind: raster/data-URI/HTTP image vs standalone inline SVG. */
|
|
16
|
+
readonly kind: 'image' | 'svg';
|
|
17
|
+
/** Safe `data:image/*` or `http(s)://` URL (for `kind: 'image'`), or sanitized SVG markup (for `kind: 'svg'`). */
|
|
18
|
+
readonly source: string;
|
|
19
|
+
/** Human-readable caption or alt text. */
|
|
20
|
+
readonly alt: string;
|
|
21
|
+
}
|
|
22
|
+
/** Options bounding fallback media extraction. */
|
|
23
|
+
export interface ExtractMediaOptions {
|
|
24
|
+
/** Maximum UTF-8 bytes allowed for any single extracted item. */
|
|
25
|
+
readonly maxContentBytes: number;
|
|
26
|
+
/** Maximum total items returned per Turn. */
|
|
27
|
+
readonly maxItems?: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Blank out fenced code blocks (`` ``` `` or `~~~`) and inline code spans (`` `...` ``)
|
|
31
|
+
* while preserving string length so downstream prose scanning never matches code examples
|
|
32
|
+
* or fences already handled by `conversation.chat.markdown.fence`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function stripMarkdownCode(markdown: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Extract fallback media items (`data:image/*` Markdown images, raw HTML `<img>` tags,
|
|
37
|
+
* and raw inline `<svg>...</svg>` blocks) from Assistant prose.
|
|
38
|
+
*
|
|
39
|
+
* Returns items in document appearance order, deduplicated and bounded by `maxContentBytes`
|
|
40
|
+
* and `maxItems`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractFallbackMedia(markdown: string, options: ExtractMediaOptions): ExtractedMediaItem[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure runtime state primitives shared by the sandbox iframe host and Artifact workbench:
|
|
3
|
+
* - LRU pool capping concurrently active interactive sandboxes
|
|
4
|
+
* - Strict `postMessage` frame parser with token verification and height clamping
|
|
5
|
+
* - Session-aware in-memory Artifact store with subscription support
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-renderer/shared/sandbox-core
|
|
8
|
+
*/
|
|
9
|
+
/** Parsed, validated message emitted by a sandboxed interactive iframe. */
|
|
10
|
+
export type ParsedSandboxMessage = {
|
|
11
|
+
readonly type: 'resize';
|
|
12
|
+
readonly height: number;
|
|
13
|
+
} | {
|
|
14
|
+
readonly type: 'error';
|
|
15
|
+
readonly message: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Validate and parse a `MessageEvent.data` payload from a sandboxed iframe.
|
|
19
|
+
*
|
|
20
|
+
* Rejects anything whose `token` does not match the instance's secret token or
|
|
21
|
+
* whose `type` is outside the explicit two-event allowlist (`resize` / `error`).
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseSandboxMessage(data: unknown, expectedToken: string, minHeight: number, maxHeight: number): ParsedSandboxMessage | null;
|
|
24
|
+
/**
|
|
25
|
+
* LRU pool that bounds the number of simultaneously live interactive iframe sandboxes.
|
|
26
|
+
*
|
|
27
|
+
* Activating a new sandbox past `capacity` puts the least-recently-used sandbox
|
|
28
|
+
* to sleep via its registered `onSleep` callback so memory and Blob URLs stay bounded
|
|
29
|
+
* across long conversations.
|
|
30
|
+
*/
|
|
31
|
+
export declare class SandboxLruPool {
|
|
32
|
+
private readonly capacity;
|
|
33
|
+
private readonly active;
|
|
34
|
+
constructor(capacity: number);
|
|
35
|
+
/** Mark `id` active (or refresh its recency) and evict the oldest entry when full. */
|
|
36
|
+
activate(id: string, onSleep: () => void): void;
|
|
37
|
+
/** Refresh recency of an already active sandbox without changing its callback. */
|
|
38
|
+
touch(id: string): void;
|
|
39
|
+
/** Remove `id` from the pool without invoking its sleep callback (e.g. normal unmount). */
|
|
40
|
+
release(id: string): void;
|
|
41
|
+
/** Put every active sandbox to sleep and clear the pool (e.g. plugin teardown). */
|
|
42
|
+
sleepAll(): void;
|
|
43
|
+
/** Whether `id` is currently active in the pool. */
|
|
44
|
+
isActive(id: string): boolean;
|
|
45
|
+
/** Current number of active sandboxes. */
|
|
46
|
+
size(): number;
|
|
47
|
+
}
|
|
48
|
+
/** Presentation kind of an artifact opened inside the right Sidebar workbench or fullscreen modal. */
|
|
49
|
+
export type ArtifactKind = 'html' | 'svg' | 'code';
|
|
50
|
+
/** Stored artifact payload opened inside the right Sidebar workbench or fullscreen modal. */
|
|
51
|
+
export interface ArtifactRecord {
|
|
52
|
+
readonly id: string;
|
|
53
|
+
readonly address: string;
|
|
54
|
+
readonly kind: ArtifactKind;
|
|
55
|
+
readonly lang?: string | undefined;
|
|
56
|
+
readonly title: string;
|
|
57
|
+
readonly code: string;
|
|
58
|
+
readonly sessionId?: string | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Resource protocol name owned by `@aqian0/dsh-renderer` (`dsh-resource://dsh-renderer/...`). */
|
|
61
|
+
export declare const ARTIFACT_RESOURCE_PROTOCOL = "dsh-renderer";
|
|
62
|
+
/** Resource URI prefix used for in-memory / fence-backed right-Sidebar artifact tabs. */
|
|
63
|
+
export declare const ARTIFACT_RESOURCE_PREFIX = "dsh-resource://dsh-renderer/artifact/";
|
|
64
|
+
/** Resource URI prefix used for durable Session-backed `render_artifact` tool-call tabs. */
|
|
65
|
+
export declare const ARTIFACT_CALL_RESOURCE_PREFIX = "dsh-resource://dsh-renderer/call/";
|
|
66
|
+
/** Session coordinate encoding used in durable `render_artifact` resource addresses. */
|
|
67
|
+
export type ArtifactSessionAddress = {
|
|
68
|
+
readonly kind: 'session';
|
|
69
|
+
readonly sessionId: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'subagent';
|
|
72
|
+
readonly parentSessionId: string;
|
|
73
|
+
readonly childSessionId: string;
|
|
74
|
+
readonly mode: 'one-shot' | 'continuable' | 'unknown';
|
|
75
|
+
};
|
|
76
|
+
/** Parsed durable `render_artifact` call resource address. */
|
|
77
|
+
export interface ArtifactCallAddress {
|
|
78
|
+
readonly session: ArtifactSessionAddress;
|
|
79
|
+
readonly callId: string;
|
|
80
|
+
}
|
|
81
|
+
/** Build a canonical `dsh-resource://` address for one Artifact id. */
|
|
82
|
+
export declare function artifactAddressFor(id: string): string;
|
|
83
|
+
/** Extract the Artifact id from a `dsh-resource://dsh-renderer/artifact/<id>` address. */
|
|
84
|
+
export declare function parseArtifactAddress(address: string): string | null;
|
|
85
|
+
/** Build a durable Session-backed `dsh-resource://` address for one `render_artifact` call. */
|
|
86
|
+
export declare function artifactCallAddressFor(target: ArtifactCallAddress): string;
|
|
87
|
+
/** Parse and validate a durable `dsh-resource://dsh-renderer/call/...` address. */
|
|
88
|
+
export declare function parseArtifactCallAddress(address: string): ArtifactCallAddress | null;
|
|
89
|
+
/** Return whether `address` is a well-formed artifact or call resource owned by `@aqian0/dsh-renderer`. */
|
|
90
|
+
export declare function isArtifactResourceAddress(address: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Bounded in-memory store for Artifacts opened in the right Sidebar workbench
|
|
93
|
+
* or fullscreen modal fallback.
|
|
94
|
+
*/
|
|
95
|
+
export declare class ArtifactStore {
|
|
96
|
+
private readonly maxEntries;
|
|
97
|
+
private readonly records;
|
|
98
|
+
private readonly addressIndex;
|
|
99
|
+
private readonly listeners;
|
|
100
|
+
private modalArtifactId;
|
|
101
|
+
private seq;
|
|
102
|
+
constructor(maxEntries?: number);
|
|
103
|
+
/** Insert or update an artifact, returning the stored record. */
|
|
104
|
+
put(input: {
|
|
105
|
+
readonly id?: string | undefined;
|
|
106
|
+
readonly address?: string | undefined;
|
|
107
|
+
readonly kind: ArtifactKind;
|
|
108
|
+
readonly lang?: string | undefined;
|
|
109
|
+
readonly title: string;
|
|
110
|
+
readonly code: string;
|
|
111
|
+
readonly sessionId?: string | undefined;
|
|
112
|
+
}): ArtifactRecord;
|
|
113
|
+
/** Look up one artifact by id. */
|
|
114
|
+
get(id: string): ArtifactRecord | undefined;
|
|
115
|
+
/** Look up one artifact by its `dsh-resource://` address (`/artifact/...` or `/call/...`). */
|
|
116
|
+
getByAddress(address: string): ArtifactRecord | undefined;
|
|
117
|
+
/** Open an artifact inside the fullscreen modal fallback. */
|
|
118
|
+
openModal(id: string): void;
|
|
119
|
+
/** Close the fullscreen modal fallback. */
|
|
120
|
+
closeModal(): void;
|
|
121
|
+
/** Current artifact displayed in the fullscreen modal fallback, if any. */
|
|
122
|
+
getModalArtifact(): ArtifactRecord | undefined;
|
|
123
|
+
/** Subscribe to store updates (`useSyncExternalStore` compatible). */
|
|
124
|
+
subscribe(listener: () => void): () => void;
|
|
125
|
+
/** Drop all artifacts and listeners on plugin teardown. */
|
|
126
|
+
clear(): void;
|
|
127
|
+
private emit;
|
|
128
|
+
}
|