@alexpeng/dsh-custom-plugin 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 +201 -0
- package/README.i18n.yaml +7 -0
- package/README.md +146 -0
- package/README.zh.md +146 -0
- package/cordis.patch.yml +13 -0
- package/lib/client.js +4570 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +6252 -0
- package/lib/types/client/api.d.ts +85 -0
- package/lib/types/client/custom.d.ts +44 -0
- package/lib/types/client/index.d.ts +25 -0
- package/lib/types/client/mermaid-url.d.ts +14 -0
- package/lib/types/client/styles.d.ts +7 -0
- package/lib/types/credentials.d.ts +18 -0
- package/lib/types/dsh-home.d.ts +15 -0
- package/lib/types/extract.d.ts +54 -0
- package/lib/types/host-service.d.ts +130 -0
- package/lib/types/index.d.ts +15 -0
- package/lib/types/loopback.d.ts +22 -0
- package/lib/types/mount-once.d.ts +23 -0
- package/lib/types/protocol.d.ts +111 -0
- package/lib/types/routes.d.ts +13 -0
- package/lib/types/state.d.ts +22 -0
- package/lib/types/usage.d.ts +30 -0
- package/package.json +79 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser transport for dsh-custom-plugin: plain same-origin fetch against
|
|
3
|
+
* the host routes. Every call returns the `{ ok }` envelope the host writes;
|
|
4
|
+
* failures surface as `{ ok: false, error }` instead of throwing.
|
|
5
|
+
* @module @alexpeng/dsh-custom-plugin/client/api
|
|
6
|
+
*/
|
|
7
|
+
import { type CustomPluginConfig, type CustomPluginState, type TimelineItem } from '../protocol.ts';
|
|
8
|
+
/** State edit the browser sends to the host. */
|
|
9
|
+
export interface StateEdit {
|
|
10
|
+
cfg?: Partial<CustomPluginConfig>;
|
|
11
|
+
folders?: CustomPluginState['folders'];
|
|
12
|
+
prompts?: CustomPluginState['prompts'];
|
|
13
|
+
stars?: CustomPluginState['stars'];
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Balance payload as the host reports it. */
|
|
17
|
+
export interface BalancePayload {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
keyConfigured: boolean;
|
|
20
|
+
balance?: {
|
|
21
|
+
currency: string;
|
|
22
|
+
total: string;
|
|
23
|
+
granted: string;
|
|
24
|
+
toppedUp: string;
|
|
25
|
+
} | null;
|
|
26
|
+
error?: string | null;
|
|
27
|
+
usageToday?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/** Read the whole state document. */
|
|
30
|
+
export declare function apiStateGet(): Promise<{
|
|
31
|
+
ok: true;
|
|
32
|
+
data: CustomPluginState;
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
error?: string;
|
|
36
|
+
}>;
|
|
37
|
+
/** Persist a state edit. */
|
|
38
|
+
export declare function apiStateSave(edit: StateEdit): Promise<{
|
|
39
|
+
ok: true;
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
error?: string;
|
|
43
|
+
}>;
|
|
44
|
+
/** Timeline nodes for one session. */
|
|
45
|
+
export declare function apiTimelineGet(sessionId: string, afterSeq?: number): Promise<{
|
|
46
|
+
ok: true;
|
|
47
|
+
sessionId: string;
|
|
48
|
+
items: TimelineItem[];
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
error?: string;
|
|
52
|
+
}>;
|
|
53
|
+
/** Export one session in the given format. */
|
|
54
|
+
export declare function apiExportRun(sessionId: string, format: string): Promise<{
|
|
55
|
+
ok: true;
|
|
56
|
+
content: string;
|
|
57
|
+
fileName: string;
|
|
58
|
+
mime: string;
|
|
59
|
+
} | {
|
|
60
|
+
ok: false;
|
|
61
|
+
error?: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** DeepSeek balance. */
|
|
64
|
+
export declare function apiBalanceGet(): Promise<BalancePayload>;
|
|
65
|
+
/** Re-scan today's session logs for usage. */
|
|
66
|
+
export declare function apiUsageScan(): Promise<{
|
|
67
|
+
ok: true;
|
|
68
|
+
usageToday: Record<string, unknown>;
|
|
69
|
+
scannedSessions: number;
|
|
70
|
+
} | {
|
|
71
|
+
ok: false;
|
|
72
|
+
error?: string;
|
|
73
|
+
}>;
|
|
74
|
+
/** Fetch the Mermaid engine into the host cache. */
|
|
75
|
+
export declare function apiMermaidFetch(): Promise<{
|
|
76
|
+
ok: true;
|
|
77
|
+
bytes: number;
|
|
78
|
+
} | {
|
|
79
|
+
ok: false;
|
|
80
|
+
error?: string;
|
|
81
|
+
}>;
|
|
82
|
+
/** Best-effort diagnostics report. */
|
|
83
|
+
export declare function apiDiagReport(message: string): void;
|
|
84
|
+
/** Host diagnostics for the About tab. */
|
|
85
|
+
export declare function apiDebugInfo(): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser half of dsh-custom-plugin: the Custom convenience suite UI.
|
|
3
|
+
*
|
|
4
|
+
* A single mutable store (`S`) drives every surface through a lightweight
|
|
5
|
+
* listener set; components re-render on `setS`. The file ports the earlier
|
|
6
|
+
* dynamic-plugin implementation: React is a platform import, static styles
|
|
7
|
+
* are injected through one owned style element (styles.ts), dynamic body
|
|
8
|
+
* styles (background / aurora / global glass) extend it, and host calls go
|
|
9
|
+
* over `/api/custom-plugin` fetch routes.
|
|
10
|
+
* @module @alexpeng/dsh-custom-plugin/client/custom
|
|
11
|
+
*/
|
|
12
|
+
import type { SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots';
|
|
13
|
+
import type { SessionListState, TurnLocation, WorkspaceListState } from '@deepseek-ai/dsh-client-runtime/client';
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
+
/** Minimal input-state face the input dock owner provides. */
|
|
16
|
+
interface InputStateLike {
|
|
17
|
+
draft?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Minimal input-actions face the framework injects into input-region slots. */
|
|
20
|
+
interface InputActionsLike {
|
|
21
|
+
setDraft(text: string, editRange?: unknown): void;
|
|
22
|
+
}
|
|
23
|
+
/** Palette of 20 muted low-saturation backgrounds (with matching tab colors).
|
|
24
|
+
* 天青灰 leads the list: it is the install default and renders first among
|
|
25
|
+
* the palette swatches, right after 无颜色 / 极光. */
|
|
26
|
+
export declare const PALETTE: Array<[string, string, string]>;
|
|
27
|
+
/** Public component props (the product slot system injects these). */
|
|
28
|
+
export interface OverlayProps {
|
|
29
|
+
useSessions: SnapshotSelectorHook<SessionListState>;
|
|
30
|
+
useWorkspaces: SnapshotSelectorHook<WorkspaceListState>;
|
|
31
|
+
}
|
|
32
|
+
export interface QuoteDockProps {
|
|
33
|
+
input: InputStateLike;
|
|
34
|
+
inputActions: InputActionsLike;
|
|
35
|
+
}
|
|
36
|
+
export interface TurnTailProps {
|
|
37
|
+
turn: TurnLocation;
|
|
38
|
+
seq: number;
|
|
39
|
+
openFile: (path: string) => void;
|
|
40
|
+
matched?: number | null;
|
|
41
|
+
}
|
|
42
|
+
/** Install the whole Custom UI into the client context. Returns a disposer that unregisters every slot entry. */
|
|
43
|
+
export declare function installCustomPlugin(ctx: Context, reportDiag: (message: string) => void): () => void;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-half entry for dsh-custom-plugin.
|
|
3
|
+
*
|
|
4
|
+
* Mounts the Custom UI surfaces (overlay, timeline, folders, prompts,
|
|
5
|
+
* balance, quote reply) through the nine slot injections. The slots ledger is
|
|
6
|
+
* the only coupling point: the declarations are provided by the web shell
|
|
7
|
+
* itself, so this plugin needs no family-side integration to work. All
|
|
8
|
+
* surfaces ship plain Chinese copy, with no i18n registration and no polling
|
|
9
|
+
* additions.
|
|
10
|
+
* @module @alexpeng/dsh-custom-plugin/client
|
|
11
|
+
*/
|
|
12
|
+
import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client';
|
|
13
|
+
/**
|
|
14
|
+
* Required services. Deliberately empty: every surface is looked up lazily
|
|
15
|
+
* (with a graceful no-op fallback), so this plugin can never sit "pending
|
|
16
|
+
* (waiting for services)" — a fiber that waits on a service name the client
|
|
17
|
+
* runtime never provides would block the whole web boot behind the
|
|
18
|
+
* "Loading plugins…" gate forever.
|
|
19
|
+
*/
|
|
20
|
+
export declare const inject: never[];
|
|
21
|
+
/**
|
|
22
|
+
* Mount the Custom suite.
|
|
23
|
+
* @param ctx - client root context.
|
|
24
|
+
*/
|
|
25
|
+
export declare function apply(ctx: ClientContext): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mermaid.live editor link builder.
|
|
3
|
+
*
|
|
4
|
+
* mermaid.live restores a diagram from `#pako:` + base64url of a DEFLATE
|
|
5
|
+
* (zlib) compressed JSON state `{ code, mermaid: { theme } }` — the same
|
|
6
|
+
* bytes `pako.deflate` produces. A plain base64url of the raw JSON (without
|
|
7
|
+
* compressing it) leaves the editor unable to inflate the payload, and the
|
|
8
|
+
* link opens an empty diagram. This module compresses for real and keeps the
|
|
9
|
+
* uncompressed payload only as a fallback for browsers without
|
|
10
|
+
* CompressionStream.
|
|
11
|
+
* @module @alexpeng/dsh-custom-plugin/client/mermaid-url
|
|
12
|
+
*/
|
|
13
|
+
/** Build the `https://mermaid.live/edit#pako:…` share link for one diagram. */
|
|
14
|
+
export declare function mermaidLiveUrl(code: string): Promise<string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static styles for the Custom suite, injected as one owned <style> tag at
|
|
3
|
+
* install time (removed by the disposer). Global class names are prefixed
|
|
4
|
+
* vx- and must not be scoped by CSS Modules.
|
|
5
|
+
* @module @alexpeng/dsh-custom-plugin/client/styles
|
|
6
|
+
*/
|
|
7
|
+
export declare const STATIC_CSS = "/* dsh-custom-plugin static styles. Every rule is global by design: the UI\n * mounts into product slots and overlays, so class names are prefixed vx-\n * and must not be scoped by CSS Modules. Dynamic rules (body background,\n * aurora gradient, global-glass blur) are managed at runtime by a style\n * element in custom.tsx and do not live here. */\n.vx-root {\n position: fixed;\n inset: 0;\n pointer-events: none;\n z-index: 2147483000;\n font-family: ui-sans-serif, system-ui, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;\n }\n .vx-fx {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n }\n .vx-anchor {\n display: inline-block;\n width: 0;\n height: 1px;\n vertical-align: bottom;\n }\n .vx-turn-actions {\n display: inline-flex;\n gap: 4px;\n margin-left: 10px;\n vertical-align: middle;\n align-items: center;\n }\n .vx-chip {\n pointer-events: auto;\n border: 1px solid rgba(128, 140, 160, .4);\n background: rgba(255, 255, 255, .16);\n color: inherit;\n border-radius: 8px;\n padding: 2px 8px;\n font-size: 11px;\n cursor: pointer;\n backdrop-filter: blur(6px);\n text-decoration: none;\n display: inline-flex;\n align-items: center;\n gap: 3px;\n }\n .vx-chip:hover {\n background: rgba(255, 255, 255, .28);\n }\n .vx-link {\n text-decoration: none;\n }\n .vx-glass {\n border-radius: 16px;\n background: rgba(255, 255, 255, .64);\n -webkit-backdrop-filter: blur(9px) saturate(1.22);\n backdrop-filter: blur(9px) saturate(1.22);\n box-shadow: 0 0 1px 1px rgba(17, 17, 26, .07) inset, 0 1px 2px rgba(17, 17, 26, .05) inset, 0px 4px 16px rgba(17, 17, 26, .05), 0px 8px 24px rgba(17, 17, 26, .05), 0px 16px 56px rgba(17, 17, 26, .05);\n }\n @media (prefers-color-scheme: dark) {\n .vx-glass {\n background: rgba(13, 17, 25, .62);\n color: #eef1f7;\n }\n }\n .vx-liquid .vx-glass {\n background: rgba(255, 255, 255, .06);\n backdrop-filter: url(#vx-lg);\n -webkit-backdrop-filter: url(#vx-lg);\n }\n @media (prefers-color-scheme: dark) {\n .vx-liquid .vx-glass {\n background: rgba(0, 0, 0, .06);\n }\n }\n @supports not (backdrop-filter: url(#vx-lg)) {\n .vx-liquid .vx-glass {\n background: rgba(255, 255, 255, .64);\n backdrop-filter: blur(9px) saturate(1.22);\n -webkit-backdrop-filter: blur(9px) saturate(1.22);\n }\n @media (prefers-color-scheme: dark) {\n .vx-liquid .vx-glass {\n background: rgba(13, 17, 25, .62);\n }\n }\n }\n .vx-liquid .vx-pattern {\n background-image: radial-gradient(rgba(150, 150, 160, .5) 3px, transparent 3px);\n background-size: 24px 24px;\n -webkit-mask-image: radial-gradient(ellipse at top, transparent 20%, black);\n mask-image: radial-gradient(ellipse at top, transparent 20%, black);\n animation: vx-pattern-move 25000ms linear infinite;\n }\n @media (prefers-color-scheme: dark) {\n .vx-liquid .vx-pattern {\n background-image: radial-gradient(rgba(110, 110, 128, .5) 3px, transparent 3px);\n }\n }\n .vx-pattern {\n position: absolute;\n inset: 0;\n pointer-events: none;\n z-index: -1;\n background-image: radial-gradient(rgba(150, 150, 160, .42) 1px, transparent 1px);\n background-size: 24px 24px;\n -webkit-mask-image: radial-gradient(ellipse at center, transparent 30%, black 100%);\n mask-image: radial-gradient(ellipse at center, transparent 30%, black 100%);\n animation: vx-pattern-move 10000ms linear infinite;\n }\n @media (prefers-color-scheme: dark) {\n .vx-pattern {\n background-image: radial-gradient(rgba(100, 100, 116, .5) 1px, transparent 1px);\n }\n }\n @keyframes vx-pattern-move {\n from {\n background-position: 0 0;\n }\n to {\n background-position: 0 24px;\n }\n }\n @keyframes vx-aurora {\n 0% {\n background-position: 0% 50%;\n }\n 50% {\n background-position: 100% 50%;\n }\n 100% {\n background-position: 0% 50%;\n }\n }\n .vx-rail {\n position: absolute;\n width: 12px;\n border-radius: 8px;\n background: rgba(120, 130, 150, .18);\n border: 1px solid rgba(120, 130, 150, .25);\n pointer-events: auto;\n touch-action: none;\n box-sizing: border-box;\n }\n .vx-rail.right {\n right: 4px;\n }\n .vx-rail.left {\n left: 56px;\n }\n /* When the rail is active it substitutes the native scrollbar: the scrollport\n carrying the vx-rail-scroller class (added by the client when it resolves\n the chat scrollport) hides its own bar so only one scroll affordance\n remains. scrollbar-gutter: stable on the shell keeps the layout width. */\n .vx-rail-scroller {\n scrollbar-width: none;\n }\n .vx-rail-scroller::-webkit-scrollbar {\n display: none;\n }\n .vx-thumb {\n position: absolute;\n left: 1px;\n right: 1px;\n border-radius: 8px;\n background: rgba(90, 105, 135, .5);\n border: 1px solid rgba(255, 255, 255, .35);\n box-sizing: border-box;\n }\n .vx-thumb:hover {\n background: rgba(90, 105, 135, .7);\n }\n .vx-dot {\n position: absolute;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 10px;\n height: 10px;\n border-radius: 50%;\n background: rgba(70, 85, 110, .92);\n border: 2px solid rgba(255, 255, 255, .92);\n box-shadow: 0 1px 3px rgba(0, 0, 0, .35);\n pointer-events: auto;\n cursor: pointer;\n transition: transform .12s;\n padding: 0;\n }\n .vx-dot:hover {\n transform: translate(-50%, -50%) scale(1.35);\n }\n .vx-dot.star {\n background: #c9a24b;\n border-color: #f3e3bd;\n }\n @media (prefers-color-scheme: dark) {\n .vx-dot {\n background: rgba(205, 215, 230, .95);\n border-color: rgba(28, 34, 46, .9);\n }\n .vx-thumb {\n background: rgba(165, 180, 205, .45);\n }\n }\n .vx-rail-pop {\n position: absolute;\n pointer-events: auto;\n padding: 10px 12px;\n width: 300px;\n font-size: 12px;\n line-height: 1.55;\n z-index: 5;\n }\n /* Class = which side the rail sits on; the card must open toward the page\n content. It is a child of the 12px-wide rail, so right:20px puts it left\n of the rail and left:20px puts it right (20px = rail width + 8px gap). */\n .vx-rail-pop.right {\n right: 20px;\n }\n .vx-rail-pop.left {\n left: 20px;\n }\n .vx-pop-time {\n color: #6d7689;\n font-size: 11px;\n margin-bottom: 4px;\n }\n .vx-pop-text {\n white-space: pre-wrap;\n word-break: break-word;\n max-height: 150px;\n overflow: hidden;\n margin-bottom: 8px;\n }\n .vx-pop-row {\n display: flex;\n gap: 5px;\n flex-wrap: wrap;\n align-items: center;\n }\n .vx-balance-wrap {\n display: inline-flex;\n align-items: center;\n position: relative;\n }\n .vx-balance-text {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 3px 10px;\n border-radius: 8px;\n font-size: 12.5px;\n color: inherit;\n background: rgba(127, 164, 224, .16);\n border: 1px solid rgba(127, 164, 224, .4);\n cursor: default;\n white-space: nowrap;\n }\n .vx-balance-text:hover {\n background: rgba(127, 164, 224, .28);\n }\n .vx-balance-text.vx-balance-pinned {\n background: rgba(127, 164, 224, .36);\n border-color: rgba(127, 164, 224, .8);\n }\n .vx-balance-head {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n margin-bottom: 8px;\n }\n .vx-balance-today {\n opacity: .75;\n font-size: 11.5px;\n }\n .vx-balance-hover {\n position: absolute;\n top: calc(100% + 8px);\n right: 0;\n z-index: 70;\n width: 360px;\n max-height: 480px;\n overflow: auto;\n padding: 12px;\n color: #20242e;\n font-size: 12px;\n pointer-events: auto;\n }\n @media (prefers-color-scheme: dark) {\n .vx-balance-hover {\n color: #e8ebf2;\n }\n }\n .vx-balance-lines {\n font-size: 13px;\n margin: 6px 0;\n }\n .vx-header-btn {\n display: inline-flex;\n align-items: center;\n gap: 5px;\n padding: 4px 10px;\n border-radius: 8px;\n font-size: 12.5px;\n color: inherit;\n background: rgba(127, 164, 224, .16);\n border: 1px solid rgba(127, 164, 224, .4);\n cursor: pointer;\n white-space: nowrap;\n }\n .vx-header-btn:hover {\n background: rgba(127, 164, 224, .3);\n }\n .vx-quote-btn {\n position: absolute;\n transform: translate(-50%, -100%);\n pointer-events: auto;\n background: rgba(40, 48, 64, .96);\n color: #eef1f7;\n border: 1px solid rgba(255, 255, 255, .25);\n padding: 5px 12px;\n border-radius: 9px;\n font-size: 12px;\n cursor: pointer;\n box-shadow: 0 6px 18px rgba(0, 0, 0, .28);\n display: inline-flex;\n align-items: center;\n gap: 5px;\n }\n .vx-panel {\n position: absolute;\n width: 430px;\n max-width: calc(100vw - 40px);\n height: min(660px, calc(100vh - 110px));\n display: flex;\n flex-direction: column;\n overflow: hidden;\n pointer-events: auto;\n color: #20242e;\n }\n @media (prefers-color-scheme: dark) {\n .vx-panel, .vx-modal, .vx-folders {\n color: #e8ebf2;\n }\n }\n .vx-panel-head {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 10px 14px;\n cursor: move;\n user-select: none;\n border-bottom: 1px solid rgba(150, 160, 180, .25);\n position: relative;\n z-index: 1;\n }\n .vx-panel-title {\n font-weight: 600;\n font-size: 13px;\n }\n .vx-panel-sub {\n font-size: 11px;\n opacity: .62;\n white-space: nowrap;\n }\n .vx-tabs {\n display: flex;\n flex-wrap: wrap;\n gap: 2px;\n padding: 8px 10px 4px;\n border-bottom: 1px solid rgba(150, 160, 180, .2);\n position: relative;\n z-index: 1;\n }\n .vx-tab {\n border: none;\n background: transparent;\n color: inherit;\n opacity: .75;\n font-size: 12px;\n padding: 5px 9px;\n border-radius: 8px;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n gap: 4px;\n }\n .vx-tab.on {\n opacity: 1;\n background: rgba(255, 255, 255, .28);\n box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);\n }\n .vx-panel-body {\n flex: 1;\n overflow: auto;\n padding: 12px 14px;\n position: relative;\n z-index: 1;\n }\n .vx-col {\n display: flex;\n flex-direction: column;\n gap: 10px;\n }\n .vx-row {\n display: flex;\n gap: 8px;\n align-items: center;\n }\n .vx-row.wrap {\n flex-wrap: wrap;\n }\n .vx-flex1 {\n flex: 1;\n }\n .vx-section-title {\n font-weight: 600;\n font-size: 12.5px;\n margin-top: 4px;\n opacity: .9;\n }\n .vx-swatches {\n display: grid;\n grid-template-columns: repeat(5, 1fr);\n gap: 6px;\n }\n .vx-swatch {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 3px;\n border: none;\n background: transparent;\n color: inherit;\n cursor: pointer;\n padding: 0;\n }\n .vx-swatch-box {\n width: 34px;\n height: 26px;\n border-radius: 8px;\n border: 2px solid rgba(120, 130, 150, .4);\n box-sizing: border-box;\n }\n .vx-swatch.on .vx-swatch-box {\n border-color: #7fa4e0;\n box-shadow: 0 0 0 2px rgba(127, 164, 224, .35);\n }\n .vx-swatch:disabled {\n opacity: .35;\n cursor: not-allowed;\n }\n .vx-swatch-label {\n font-size: 10px;\n opacity: .85;\n }\n .vx-btn {\n pointer-events: auto;\n border: 1px solid rgba(128, 140, 160, .4);\n background: rgba(255, 255, 255, .16);\n color: inherit;\n border-radius: 9px;\n padding: 6px 12px;\n font-size: 12px;\n cursor: pointer;\n display: inline-flex;\n align-items: center;\n gap: 5px;\n }\n .vx-btn:hover {\n background: rgba(255, 255, 255, .28);\n }\n .vx-btn.on {\n background: rgba(127, 164, 224, .35);\n border-color: rgba(127, 164, 224, .8);\n }\n .vx-btn:disabled {\n opacity: .5;\n cursor: default;\n }\n .vx-btn-sm {\n padding: 2px 8px;\n font-size: 11px;\n }\n .vx-btn-danger {\n background: rgba(214, 88, 88, .22);\n border-color: rgba(214, 88, 88, .55);\n }\n .vx-btn.big {\n padding: 10px 16px;\n font-size: 13px;\n }\n .vx-input {\n flex: 1;\n min-width: 0;\n border: 1px solid rgba(128, 140, 160, .4);\n background: rgba(255, 255, 255, .16);\n color: inherit;\n border-radius: 9px;\n padding: 6px 10px;\n font-size: 12px;\n }\n .vx-textarea {\n border: 1px solid rgba(128, 140, 160, .4);\n background: rgba(255, 255, 255, .16);\n color: inherit;\n border-radius: 9px;\n padding: 6px 10px;\n font-size: 12px;\n resize: vertical;\n font-family: inherit;\n }\n .vx-toggle-row {\n display: flex;\n gap: 8px;\n align-items: center;\n font-size: 12.5px;\n }\n .vx-muted {\n color: rgba(120, 128, 148, .95);\n font-size: 11.5px;\n }\n .vx-error {\n color: #d85858;\n font-size: 12px;\n }\n .vx-pad {\n padding: 12px;\n }\n .vx-pad-sm {\n padding: 6px 2px;\n }\n .vx-list {\n display: flex;\n flex-direction: column;\n gap: 4px;\n max-height: 300px;\n overflow: auto;\n }\n .vx-list-item {\n text-align: left;\n border: none;\n background: rgba(255, 255, 255, .1);\n color: inherit;\n border-radius: 8px;\n padding: 6px 10px;\n font-size: 12px;\n cursor: pointer;\n }\n .vx-list-item:hover {\n background: rgba(255, 255, 255, .22);\n }\n .vx-check-row {\n display: flex;\n gap: 8px;\n align-items: center;\n font-size: 12.5px;\n padding: 4px 2px;\n }\n .vx-check-title {\n flex: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n .vx-badge {\n background: rgba(127, 164, 224, .3);\n border-radius: 8px;\n padding: 0 6px;\n font-size: 10px;\n }\n .vx-table {\n width: 100%;\n border-collapse: collapse;\n font-size: 11.5px;\n }\n .vx-table th, .vx-table td {\n border: 1px solid rgba(128, 140, 160, .3);\n padding: 4px 6px;\n text-align: right;\n }\n .vx-table th:first-child, .vx-table td:first-child {\n text-align: left;\n }\n .vx-folder {\n display: flex;\n flex-direction: column;\n }\n .vx-folder-head {\n display: flex;\n gap: 5px;\n align-items: center;\n padding: 5px 4px;\n border-radius: 9px;\n cursor: grab;\n }\n .vx-folder-head:hover {\n background: rgba(255, 255, 255, .14);\n }\n .vx-folder-head.drop-inside {\n background: rgba(127, 164, 224, .3);\n outline: 1px dashed rgba(127, 164, 224, .8);\n }\n .vx-folder-head.drop-before {\n box-shadow: 0 -2px 0 0 rgba(127, 164, 224, .9);\n }\n .vx-folder-head.drop-after {\n box-shadow: 0 2px 0 0 rgba(127, 164, 224, .9);\n }\n .vx-folder-name {\n font-size: 12.5px;\n font-weight: 600;\n flex: 1;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n .vx-folder-body {\n border-left: 1px dashed rgba(128, 140, 160, .35);\n margin-left: 14px;\n padding-left: 6px;\n display: flex;\n flex-direction: column;\n gap: 2px;\n }\n .vx-item-row {\n display: flex;\n gap: 5px;\n align-items: center;\n padding: 3px 4px;\n border-radius: 8px;\n }\n .vx-item-row:hover {\n background: rgba(255, 255, 255, .12);\n }\n .vx-item-name {\n flex: 1;\n text-align: left;\n border: none;\n background: transparent;\n color: inherit;\n font-size: 12px;\n cursor: pointer;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n padding: 0;\n }\n .vx-mini {\n border: none;\n background: transparent;\n color: inherit;\n opacity: .75;\n cursor: pointer;\n padding: 2px;\n border-radius: 6px;\n display: inline-flex;\n align-items: center;\n }\n .vx-mini:hover {\n opacity: 1;\n background: rgba(255, 255, 255, .2);\n }\n .vx-form {\n display: flex;\n flex-direction: column;\n gap: 6px;\n border: 1px dashed rgba(128, 140, 160, .4);\n border-radius: 10px;\n padding: 8px;\n }\n .vx-prompt-card {\n border: 1px solid rgba(128, 140, 160, .3);\n background: rgba(255, 255, 255, .1);\n border-radius: 10px;\n padding: 8px 10px;\n }\n .vx-prompt-title {\n font-weight: 600;\n font-size: 12.5px;\n }\n .vx-prompt-body {\n margin-top: 4px;\n font-size: 11.5px;\n opacity: .85;\n white-space: pre-wrap;\n word-break: break-word;\n max-height: 72px;\n overflow: hidden;\n }\n .vx-modal-mask {\n position: absolute;\n inset: 0;\n pointer-events: auto;\n background: rgba(8, 10, 16, .4);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 60;\n }\n .vx-modal {\n position: relative;\n width: min(760px, 92vw);\n max-height: 82vh;\n overflow: auto;\n padding: 16px;\n color: #20242e;\n pointer-events: auto;\n }\n .vx-pop-head {\n display: flex;\n gap: 8px;\n align-items: center;\n margin-bottom: 8px;\n font-weight: 600;\n font-size: 13px;\n }\n .vx-svgbox {\n overflow: auto;\n background: rgba(12, 14, 20, .6);\n border-radius: 12px;\n padding: 14px;\n }\n .vx-svgbox svg {\n max-width: 100%;\n height: auto;\n }\n .vx-pre {\n white-space: pre-wrap;\n word-break: break-all;\n font-size: 10.5px;\n opacity: .85;\n }\n .vx-toasts {\n position: absolute;\n left: 50%;\n bottom: 26px;\n transform: translateX(-50%);\n display: flex;\n flex-direction: column;\n gap: 8px;\n align-items: center;\n pointer-events: auto;\n z-index: 80;\n }\n .vx-toast {\n display: flex;\n gap: 10px;\n align-items: center;\n color: #f2f4f8;\n background: rgba(26, 32, 44, .92);\n border: 1px solid rgba(255, 255, 255, .12);\n padding: 8px 14px;\n border-radius: 12px;\n font-size: 12.5px;\n box-shadow: 0 10px 30px rgba(0, 0, 0, .3);\n max-width: 560px;\n backdrop-filter: blur(9px);\n -webkit-backdrop-filter: blur(9px);\n }\n @media (prefers-color-scheme: dark) {\n .vx-toast {\n background: rgba(18, 22, 30, .94);\n }\n }\n .vx-foot-btn {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n border: 1px solid rgba(127, 164, 224, .4);\n background: rgba(127, 164, 224, .14);\n color: inherit;\n cursor: pointer;\n padding: 4px 10px;\n border-radius: 10px;\n margin: 2px;\n }\n .vx-foot-btn:hover {\n background: rgba(127, 164, 224, .3);\n }\n .vx-foot-label {\n font-size: 12px;\n }\n .vx-folders {\n position: fixed;\n left: 12px;\n bottom: 60px;\n width: 272px;\n max-height: min(560px, calc(100vh - 220px));\n display: flex;\n flex-direction: column;\n overflow: hidden;\n pointer-events: auto;\n color: #20242e;\n z-index: 55;\n }\n /* \u5934\u90E8\u884C\uFF08\u56FE\u6807 + \u6807\u9898 + \u6309\u94AE\uFF09\u4E0B\u79FB\u5E76\u62C9\u5F00\u4E0E\u5BB9\u5668\u8FB9\u7F18\u7684\u95F4\u8DDD */\n .vx-folders .vx-pop-head {\n padding: 14px 14px 0;\n }\n .vx-folders-body {\n flex: 1;\n overflow: auto;\n padding: 4px 14px 12px;\n position: relative;\n z-index: 1;\n }\n .vx-prompt-pop {\n position: fixed;\n width: 320px;\n max-height: 420px;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n pointer-events: auto;\n color: #20242e;\n z-index: 65;\n padding: 10px 12px;\n }\n .vx-settings-page {\n display: flex;\n flex-direction: column;\n gap: 14px;\n max-width: 720px;\n }";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH credential refs reader for dsh-custom-plugin.
|
|
3
|
+
*
|
|
4
|
+
* DSH keeps model API keys in `$DSH_HOME/.credentials.yaml` as a flat
|
|
5
|
+
* `refs:` block (`DEEPSEEK_API_KEY: sk-...`) and injects them per outgoing
|
|
6
|
+
* request — they are NOT exported to the process environment. The balance
|
|
7
|
+
* panel therefore reads the same file so a key configured once in DSH is
|
|
8
|
+
* picked up automatically instead of requiring a second paste in the plugin.
|
|
9
|
+
* @module @alexpeng/dsh-custom-plugin/credentials
|
|
10
|
+
*/
|
|
11
|
+
/** File name of the DSH credential refs document. */
|
|
12
|
+
export declare const CREDENTIALS_FILE = ".credentials.yaml";
|
|
13
|
+
/** Environment/ref keys that may hold the DeepSeek balance credential. */
|
|
14
|
+
export declare const DEEPSEEK_REF_KEYS: readonly ["DEEPSEEK_API_KEY", "DEEPSEEK_KEY", "DEEPSEEK_TOKEN"];
|
|
15
|
+
/** Parse the `refs:` block of DSH's credentials YAML (flat `NAME: value`). */
|
|
16
|
+
export declare function parseCredentialsRefs(text: string): Record<string, string>;
|
|
17
|
+
/** Read the DeepSeek credential from DSH's credentials file ('' when absent). */
|
|
18
|
+
export declare function readDeepSeekCredential(home?: string): Promise<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH_HOME resolution for the plugin's Host half: the environment override
|
|
3
|
+
* wins, the platform home fallback follows.
|
|
4
|
+
*/
|
|
5
|
+
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
6
|
+
export declare function expandHome(path: string, home?: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the DSH home directory.
|
|
9
|
+
* @param env - process environment to read DSH_HOME from.
|
|
10
|
+
* @param home - platform home directory fallback (test seam).
|
|
11
|
+
* @returns the absolute DSH home path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveDshHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
14
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
15
|
+
export declare function dshHome(): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure extraction and export builders for dsh-custom-plugin.
|
|
3
|
+
*
|
|
4
|
+
* All functions here are side-effect free (image embedding aside, which takes
|
|
5
|
+
* an optional reader seam) so they can be unit-tested without a Cordis
|
|
6
|
+
* context. The host routes call them over {@link SessionLogSnapshot} objects
|
|
7
|
+
* from `ctx.sessionQuery`.
|
|
8
|
+
* @module @alexpeng/dsh-custom-plugin/extract
|
|
9
|
+
*/
|
|
10
|
+
import type { ImageAttachmentRef, StoredImageAttachment } from '@deepseek-ai/dsh-attachment';
|
|
11
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm';
|
|
12
|
+
import type { SessionEvent } from '@deepseek-ai/dsh-session';
|
|
13
|
+
import type { SessionLogSnapshot } from '@deepseek-ai/dsh-session-query';
|
|
14
|
+
import type { TimelineItem } from './protocol.ts';
|
|
15
|
+
/** Base64 encode bytes without relying on Buffer (browser-host parity). */
|
|
16
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
17
|
+
/** Flatten one content block into plain display text. */
|
|
18
|
+
export declare function blockText(block: ContentBlock | undefined | null): string;
|
|
19
|
+
/** Flatten a message content array into plain display text. */
|
|
20
|
+
export declare function messageText(content: readonly ContentBlock[] | undefined | null): string;
|
|
21
|
+
/** Content flags used by the timeline and the copy/rendering chips. */
|
|
22
|
+
export declare function flagsOf(text: string): {
|
|
23
|
+
hasLatex: boolean;
|
|
24
|
+
hasMathml: boolean;
|
|
25
|
+
hasMermaid: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** Extract one timeline node per direct user message from a session log. */
|
|
28
|
+
export declare function extractTurns(events: readonly SessionEvent[]): TimelineItem[];
|
|
29
|
+
/** One flattened export row. */
|
|
30
|
+
export interface ExportRow {
|
|
31
|
+
seq: number;
|
|
32
|
+
time: number;
|
|
33
|
+
kind: 'user' | 'context' | 'assistant' | 'tool-call' | 'tool-result';
|
|
34
|
+
text: string;
|
|
35
|
+
toolName?: string;
|
|
36
|
+
toolArgs?: string;
|
|
37
|
+
images?: Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
mediaType: string;
|
|
40
|
+
bytes: number;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
dataUrl?: string;
|
|
44
|
+
skipped?: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
/** Embed user-message images as data URLs when the attachment reader is available. */
|
|
48
|
+
export declare function collectImages(content: readonly ContentBlock[] | undefined | null, embed: boolean, readImage?: (ref: ImageAttachmentRef) => Promise<StoredImageAttachment>): Promise<ExportRow['images']>;
|
|
49
|
+
/** Build flattened export rows for one session log (newest 3000 kept). */
|
|
50
|
+
export declare function buildExportRows(snapshot: SessionLogSnapshot, format: 'json' | 'markdown' | 'pdf', readImage?: (ref: ImageAttachmentRef) => Promise<StoredImageAttachment>): Promise<ExportRow[]>;
|
|
51
|
+
/** Build the Markdown export document. */
|
|
52
|
+
export declare function buildMarkdown(rows: readonly ExportRow[], sessionId: string): string;
|
|
53
|
+
/** Build the print-ready HTML document (browser "Save as PDF" target). */
|
|
54
|
+
export declare function buildPdfHtml(rows: readonly ExportRow[], sessionId: string): string;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host service for dsh-custom-plugin: owns the state document and every
|
|
3
|
+
* browser-facing capability (timeline, export, balance, usage scan, Mermaid).
|
|
4
|
+
* The routes in `routes.ts` are a thin HTTP fence over this class.
|
|
5
|
+
* @module @alexpeng/dsh-custom-plugin/host-service
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import type { AttachmentStore } from '@deepseek-ai/dsh-attachment';
|
|
9
|
+
import type { SessionQueryEngine } from '@deepseek-ai/dsh-session-query';
|
|
10
|
+
import type { BalanceInfo, CustomPluginState, TimelineItem } from './protocol.ts';
|
|
11
|
+
import { type UsageRecord } from './usage.ts';
|
|
12
|
+
export type { BalanceInfo, TimelineItem };
|
|
13
|
+
/** Options the loader entry supplies to the host service. */
|
|
14
|
+
export interface CustomPluginHostOptions {
|
|
15
|
+
sessionQuery: SessionQueryEngine;
|
|
16
|
+
/** Persisted state document (mutated in place; the loader owns saving). */
|
|
17
|
+
state: CustomPluginState;
|
|
18
|
+
/** Resolve the absolute state file path for diagnostics. */
|
|
19
|
+
statePath: () => string;
|
|
20
|
+
/** Persist the state document now. */
|
|
21
|
+
saveNow: () => Promise<void>;
|
|
22
|
+
/** Record a bounded client diagnostic line. */
|
|
23
|
+
reportDiag: (message: string) => void;
|
|
24
|
+
/** Bounded diagnostic ring for the status tool. */
|
|
25
|
+
diagReports: string[];
|
|
26
|
+
/** Optional attachment store used to embed images into PDF exports. */
|
|
27
|
+
attachments?: AttachmentStore | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Host capabilities behind the routes and the agent tool. */
|
|
30
|
+
export declare class CustomPluginHost {
|
|
31
|
+
private readonly sessionQuery;
|
|
32
|
+
private readonly state;
|
|
33
|
+
private readonly statePath;
|
|
34
|
+
private readonly persistNow;
|
|
35
|
+
private readonly diagReports;
|
|
36
|
+
private readonly attachments;
|
|
37
|
+
private readonly sessionModel;
|
|
38
|
+
private readonly timelineCache;
|
|
39
|
+
private mermaidBytesValue;
|
|
40
|
+
private mermaidJs;
|
|
41
|
+
constructor(_ctx: Context, options: CustomPluginHostOptions);
|
|
42
|
+
/** Persist the state document (debounced by the loader entry). */
|
|
43
|
+
persist(): Promise<void>;
|
|
44
|
+
/** Record a bounded client diagnostic line. */
|
|
45
|
+
pushDiag(message: string): void;
|
|
46
|
+
/** Track the model of each session's latest request. */
|
|
47
|
+
rememberModel(sessionId: string, model: string | null): void;
|
|
48
|
+
forgetSession(sessionId: string): void;
|
|
49
|
+
/** Fold one assistant/message usage record into the ledger. The event time
|
|
50
|
+
* decides both the day bucket and the peak/off-peak portion. */
|
|
51
|
+
foldUsage(sessionId: string, usage: UsageRecord, time?: number): void;
|
|
52
|
+
/** Snapshot of the whole state document for the browser. */
|
|
53
|
+
stateView(): Pick<CustomPluginState, 'cfg' | 'folders' | 'prompts' | 'stars' | 'apiKey' | 'usage'>;
|
|
54
|
+
/** Apply a browser-side state edit (config, folders, prompts, stars, api key). */
|
|
55
|
+
applyEdit(edit: {
|
|
56
|
+
cfg?: Partial<CustomPluginState['cfg']>;
|
|
57
|
+
folders?: CustomPluginState['folders'];
|
|
58
|
+
prompts?: CustomPluginState['prompts'];
|
|
59
|
+
stars?: CustomPluginState['stars'];
|
|
60
|
+
apiKey?: string;
|
|
61
|
+
}): void;
|
|
62
|
+
/** Timeline nodes for one session, with a 10-second cache. */
|
|
63
|
+
timelineGet(sessionId: string, afterSeq: number): Promise<{
|
|
64
|
+
ok: true;
|
|
65
|
+
sessionId: string;
|
|
66
|
+
items: TimelineItem[];
|
|
67
|
+
} | {
|
|
68
|
+
ok: false;
|
|
69
|
+
error: string;
|
|
70
|
+
}>;
|
|
71
|
+
/** Export one session as JSON / Markdown / print-ready HTML. */
|
|
72
|
+
exportRun(sessionId: string, format: string): Promise<{
|
|
73
|
+
ok: true;
|
|
74
|
+
content: string;
|
|
75
|
+
fileName: string;
|
|
76
|
+
mime: string;
|
|
77
|
+
} | {
|
|
78
|
+
ok: false;
|
|
79
|
+
error: string;
|
|
80
|
+
}>;
|
|
81
|
+
/** Resolve the DeepSeek balance API key: state value first, then environment, then DSH credential refs. */
|
|
82
|
+
private resolveApiKey;
|
|
83
|
+
/** Query the DeepSeek balance endpoint (15s timeout). */
|
|
84
|
+
balanceGet(): Promise<{
|
|
85
|
+
ok: boolean;
|
|
86
|
+
keyConfigured: boolean;
|
|
87
|
+
balance?: BalanceInfo | null;
|
|
88
|
+
error?: string | null;
|
|
89
|
+
usageToday?: unknown;
|
|
90
|
+
available?: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
/** Re-scan the session logs and rebuild today's usage ledger. Every session
|
|
93
|
+
* is replayed but only usage events whose own timestamp falls on today are
|
|
94
|
+
* folded, so sessions created before midnight keep contributing the usage
|
|
95
|
+
* they produced today. */
|
|
96
|
+
usageScan(): Promise<{
|
|
97
|
+
ok: true;
|
|
98
|
+
usageToday: unknown;
|
|
99
|
+
scannedSessions: number;
|
|
100
|
+
} | {
|
|
101
|
+
ok: false;
|
|
102
|
+
error: string;
|
|
103
|
+
}>;
|
|
104
|
+
/** Fetch the Mermaid engine from CDN mirrors (cached for the host lifetime). */
|
|
105
|
+
mermaidFetch(): Promise<{
|
|
106
|
+
ok: true;
|
|
107
|
+
bytes: number;
|
|
108
|
+
} | {
|
|
109
|
+
ok: false;
|
|
110
|
+
error: string;
|
|
111
|
+
}>;
|
|
112
|
+
/** The cached Mermaid engine script (served at the script path). */
|
|
113
|
+
mermaidScript(): string;
|
|
114
|
+
/** Mermaid engine byte count for diagnostics. */
|
|
115
|
+
mermaidBytes(): number;
|
|
116
|
+
/** Whether any DeepSeek key source resolves (state, environment, credential
|
|
117
|
+
* file) — the honest answer behind the panel's "key configured" badge. */
|
|
118
|
+
hasApiKey(): Promise<boolean>;
|
|
119
|
+
/** Diagnostics snapshot for the status tool and the About tab. */
|
|
120
|
+
debugInfo(): Promise<{
|
|
121
|
+
statePath: string;
|
|
122
|
+
today: string;
|
|
123
|
+
usageToday: unknown;
|
|
124
|
+
mermaidBytes: number;
|
|
125
|
+
apiKeySet: boolean;
|
|
126
|
+
diagReports: string[];
|
|
127
|
+
}>;
|
|
128
|
+
private httpText;
|
|
129
|
+
private httpJson;
|
|
130
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host loader entry for dsh-custom-plugin.
|
|
3
|
+
*
|
|
4
|
+
* The Host owns the state document, the daily token-usage ledger (folded
|
|
5
|
+
* from `session/event`), the `/api/custom-plugin` routes (state, timeline,
|
|
6
|
+
* export, balance, usage scan, Mermaid fetch, diagnostics), and the
|
|
7
|
+
* `custom_plugin_status` agent tool. The browser is a same-origin view over
|
|
8
|
+
* those routes; this half has no UI of its own.
|
|
9
|
+
* @module @alexpeng/dsh-custom-plugin
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
export declare const apply: typeof applyImpl;
|
|
14
|
+
declare function applyImpl(ctx: Context): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loopback trust fence for the host routes: socket address, Host header,
|
|
3
|
+
* and browser same-origin markers.
|
|
4
|
+
*
|
|
5
|
+
* Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8, localhost
|
|
6
|
+
* hostnames, plus the browser same-origin markers (sec-fetch-site and
|
|
7
|
+
* Origin) for the request-level fence.
|
|
8
|
+
* @module @alexpeng/dsh-custom-plugin/loopback
|
|
9
|
+
*/
|
|
10
|
+
import type { IncomingMessage } from 'node:http';
|
|
11
|
+
/** IPv4 127/8 predicate (four decimal octets, first == 127). */
|
|
12
|
+
export declare function isIPv4Loopback(v4: string): boolean;
|
|
13
|
+
/** Whether a socket remote address names the loopback range (127/8, ::1, IPv4-mapped). */
|
|
14
|
+
export declare function isLoopbackAddress(address: string | undefined): boolean;
|
|
15
|
+
/** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
|
|
16
|
+
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Request-level trust fence: a loopback socket address AND a loopback Host
|
|
19
|
+
* header, plus browser same-origin markers. The socket address is
|
|
20
|
+
* authoritative; X-Forwarded-For is never trusted.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isLoopbackRequest(request: IncomingMessage): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host single-instance guard. The loader accepts a standalone install of the
|
|
3
|
+
* same package side by side with another copy (npm install vs repository
|
|
4
|
+
* link); without this guard the second instance would still re-register the
|
|
5
|
+
* same webserver routes, tools, settings namespaces, and system-prompt
|
|
6
|
+
* sections and fail the boot. mountOnce makes the second host apply a no-op
|
|
7
|
+
* for the lifetime of the first instance (the browser half is already
|
|
8
|
+
* deduped by package name in the client module host).
|
|
9
|
+
*
|
|
10
|
+
* The registry rides a global symbol so two module instances of the same
|
|
11
|
+
* package (npm copy vs repository link) still share one verdict. cordis
|
|
12
|
+
* `ctx.effect` runs its callback immediately and treats the callback's
|
|
13
|
+
* return value as the fiber disposer, so the unmarker is returned, not run.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Wrap a cordis plugin apply so the package runs at most once per process.
|
|
17
|
+
* The first mount registers normally and unmarks when its fiber disposes;
|
|
18
|
+
* any later mount of the same package name is a no-op.
|
|
19
|
+
* @param packageName - npm package identity shared by every install source.
|
|
20
|
+
* @param fn - the original plugin apply.
|
|
21
|
+
* @returns an apply of the same shape.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mountOnce<T extends (...args: any[]) => unknown>(packageName: string, fn: T): T;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire protocol shared by the host routes and the browser transport.
|
|
3
|
+
*
|
|
4
|
+
* The browser talks to the host through plain same-origin fetch against
|
|
5
|
+
* {@link CUSTOM_PLUGIN_API_PREFIX}; every handler answers with the `{ ok }`
|
|
6
|
+
* envelope below so the client can surface host errors without coupling to
|
|
7
|
+
* route details. Types here are the JSON currency only — no Cordis or React
|
|
8
|
+
* objects cross this boundary.
|
|
9
|
+
* @module @alexpeng/dsh-custom-plugin/protocol
|
|
10
|
+
*/
|
|
11
|
+
/** Prefix of every host route this plugin registers. */
|
|
12
|
+
export declare const CUSTOM_PLUGIN_API_PREFIX = "/api/custom-plugin";
|
|
13
|
+
/** Path the host serves the fetched Mermaid engine at (script src). */
|
|
14
|
+
export declare const MERMAID_SCRIPT_PATH = "/custom-plugin/mermaid.js";
|
|
15
|
+
/** Plugin appearance and behavior configuration, persisted in the host state file. */
|
|
16
|
+
export interface CustomPluginConfig {
|
|
17
|
+
/** Background preset: 'default' | 'aurora' | one of the 20 palette names. */
|
|
18
|
+
bg?: string;
|
|
19
|
+
/** Weather overlay: 'none' | 'snow' | 'rain' | 'sakura'. */
|
|
20
|
+
weather?: string;
|
|
21
|
+
/** Master glass toggle for the plugin's own surfaces. */
|
|
22
|
+
glass?: boolean;
|
|
23
|
+
/** 'frost' frosted glass or 'liquid' displacement glass. */
|
|
24
|
+
glassMode?: 'frost' | 'liquid';
|
|
25
|
+
/** Apply backdrop blur to global dialogs/menus/tooltips as well. */
|
|
26
|
+
globalGlass?: boolean;
|
|
27
|
+
/** Show the per-user-message timeline rail. */
|
|
28
|
+
timeline?: boolean;
|
|
29
|
+
/** Place the timeline rail on the left instead of the right. */
|
|
30
|
+
timelineLeft?: boolean;
|
|
31
|
+
/** Show only starred timeline nodes. */
|
|
32
|
+
starsOnly?: boolean;
|
|
33
|
+
/** Enable the selection-quote-reply feature. */
|
|
34
|
+
quote?: boolean;
|
|
35
|
+
/** Force `scroll-behavior: auto` to stop automatic jump-to-bottom. */
|
|
36
|
+
antiScroll?: boolean;
|
|
37
|
+
/** Show LaTeX / MathML copy chips under matching messages. */
|
|
38
|
+
formula?: boolean;
|
|
39
|
+
/** Show Mermaid render chips under matching messages. */
|
|
40
|
+
mermaid?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Default configuration (also the composition-layer default). */
|
|
43
|
+
export declare const DEFAULT_CONFIG: CustomPluginConfig;
|
|
44
|
+
/** One folder node in the multi-level project tree. */
|
|
45
|
+
export interface FolderNode {
|
|
46
|
+
id: string;
|
|
47
|
+
name: string;
|
|
48
|
+
children: FolderNode[];
|
|
49
|
+
sessionIds: string[];
|
|
50
|
+
workspaceIds: string[];
|
|
51
|
+
prompts: string[];
|
|
52
|
+
}
|
|
53
|
+
/** One saved prompt. */
|
|
54
|
+
export interface PromptItem {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
text: string;
|
|
58
|
+
}
|
|
59
|
+
/** Starred timeline nodes, keyed by session id then by user-message seq. */
|
|
60
|
+
export type StarsMap = Record<string, Record<string, boolean>>;
|
|
61
|
+
/** Per-model token counters for one day. */
|
|
62
|
+
export interface UsageRow {
|
|
63
|
+
in: number;
|
|
64
|
+
out: number;
|
|
65
|
+
cacheIn: number;
|
|
66
|
+
cacheW: number;
|
|
67
|
+
reason: number;
|
|
68
|
+
calls: number;
|
|
69
|
+
/** Peak-hour (Beijing 09-12 / 14-18) portion of each counter; the rest is
|
|
70
|
+
* off-peak. Optional because rows persisted before the peak/off-peak split
|
|
71
|
+
* predate these fields. */
|
|
72
|
+
peakIn?: number;
|
|
73
|
+
peakCacheIn?: number;
|
|
74
|
+
peakCacheW?: number;
|
|
75
|
+
peakOut?: number;
|
|
76
|
+
}
|
|
77
|
+
/** Day -> model -> counters. */
|
|
78
|
+
export type UsageMap = Record<string, Record<string, UsageRow>>;
|
|
79
|
+
/** The complete persisted state file shape. */
|
|
80
|
+
export interface CustomPluginState {
|
|
81
|
+
cfg: CustomPluginConfig;
|
|
82
|
+
folders: FolderNode[];
|
|
83
|
+
prompts: PromptItem[];
|
|
84
|
+
stars: StarsMap;
|
|
85
|
+
/** DeepSeek API key for the balance panel; kept out of settings config. */
|
|
86
|
+
apiKey: string;
|
|
87
|
+
usage: UsageMap;
|
|
88
|
+
}
|
|
89
|
+
/** One timeline node: one direct user message in a session. */
|
|
90
|
+
export interface TimelineItem {
|
|
91
|
+
seq: number;
|
|
92
|
+
time: number;
|
|
93
|
+
turn: number;
|
|
94
|
+
text: string;
|
|
95
|
+
imageCount: number;
|
|
96
|
+
hasLatex: boolean;
|
|
97
|
+
hasMathml: boolean;
|
|
98
|
+
hasMermaid: boolean;
|
|
99
|
+
}
|
|
100
|
+
/** Balance payload returned by the DeepSeek balance endpoint. */
|
|
101
|
+
export interface BalanceInfo {
|
|
102
|
+
currency: string;
|
|
103
|
+
total: string;
|
|
104
|
+
granted: string;
|
|
105
|
+
toppedUp: string;
|
|
106
|
+
}
|
|
107
|
+
/** Host response envelope. */
|
|
108
|
+
export type ApiResult<T> = {
|
|
109
|
+
ok: true;
|
|
110
|
+
[key: string]: unknown;
|
|
111
|
+
} & T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP routes for dsh-custom-plugin.
|
|
3
|
+
*
|
|
4
|
+
* Every route sits behind the loopback + same-origin fence (shared
|
|
5
|
+
* `loopback.ts`); the browser talks to these handlers with plain fetch. The
|
|
6
|
+
* mermaid engine script is served at its own non-API path because the browser
|
|
7
|
+
* loads it as a `<script src>`.
|
|
8
|
+
* @module @alexpeng/dsh-custom-plugin/routes
|
|
9
|
+
*/
|
|
10
|
+
import type { WebRoute } from '@deepseek-ai/dsh-host-webserver';
|
|
11
|
+
import type { CustomPluginHost } from './host-service.ts';
|
|
12
|
+
/** Build the plugin's route set. */
|
|
13
|
+
export declare function makeCustomPluginRoutes(host: CustomPluginHost): WebRoute[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-owned state store for dsh-custom-plugin.
|
|
3
|
+
*
|
|
4
|
+
* One JSON document at `$DSH_HOME/custom-plugin-state.json` holds the
|
|
5
|
+
* appearance configuration, folder tree, prompt library, starred timeline
|
|
6
|
+
* nodes, the balance API key, and the per-day token usage ledger. Writes are
|
|
7
|
+
* atomic (temp file + rename) so a crash never truncates the document.
|
|
8
|
+
* @module @alexpeng/dsh-custom-plugin/state
|
|
9
|
+
*/
|
|
10
|
+
import { type CustomPluginConfig, type CustomPluginState } from './protocol.ts';
|
|
11
|
+
/** State file name of this plugin. */
|
|
12
|
+
export declare const STATE_FILE = "custom-plugin-state.json";
|
|
13
|
+
/** Default state document. */
|
|
14
|
+
export declare function defaultState(): CustomPluginState;
|
|
15
|
+
/** Normalize a stored configuration: strip retired keys and fill defaults. */
|
|
16
|
+
export declare function normalizeCfg(raw: unknown): CustomPluginConfig;
|
|
17
|
+
/** Merge a persisted document into the default state, ignoring unknown shapes. */
|
|
18
|
+
export declare function mergeState(target: CustomPluginState, raw: unknown): void;
|
|
19
|
+
/** Load and merge the persisted document into `state`. */
|
|
20
|
+
export declare function loadStateFile(state: CustomPluginState, home?: string): Promise<string>;
|
|
21
|
+
/** Atomically persist the state document. */
|
|
22
|
+
export declare function saveStateFile(state: CustomPluginState, home?: string): Promise<void>;
|