@nelsonlongxiang/dsh-prompt-templates 0.4.4 → 0.13.2

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.
Files changed (50) hide show
  1. package/README.md +113 -62
  2. package/README_zh.md +112 -62
  3. package/cordis.patch.yml +4 -0
  4. package/lib/cli/app.js +169 -0
  5. package/lib/cli/database.js +162 -0
  6. package/lib/cli/main.js +6 -0
  7. package/lib/cli/model.js +247 -0
  8. package/lib/client/Library.js +290 -0
  9. package/lib/client/Panel.js +37 -201
  10. package/lib/client/PanelButton.js +27 -3
  11. package/lib/client/PromptTab.js +11 -0
  12. package/lib/client/api.js +16 -0
  13. package/lib/client/filter.js +27 -0
  14. package/lib/client/index.js +53 -36
  15. package/lib/client/locales.js +34 -2
  16. package/lib/client/meta.js +10 -0
  17. package/lib/client/service.js +57 -37
  18. package/lib/client/slots.js +5 -3
  19. package/lib/client/store.js +12 -1
  20. package/lib/client/tab.js +32 -0
  21. package/lib/client.js +798 -286
  22. package/lib/client.js.map +1 -1
  23. package/lib/index.js +35 -16
  24. package/lib/inject.js +236 -0
  25. package/lib/invariant.js +1 -1
  26. package/lib/store.js +108 -32
  27. package/lib/types/cli/app.d.ts +1 -0
  28. package/lib/types/cli/database.d.ts +69 -0
  29. package/lib/types/cli/main.d.ts +2 -0
  30. package/lib/types/cli/model.d.ts +62 -0
  31. package/lib/types/client/Library.d.ts +34 -0
  32. package/lib/types/client/Panel.d.ts +1 -1
  33. package/lib/types/client/PanelButton.d.ts +10 -9
  34. package/lib/types/client/PromptTab.d.ts +17 -0
  35. package/lib/types/client/api.d.ts +11 -1
  36. package/lib/types/client/filter.d.ts +10 -0
  37. package/lib/types/client/index.d.ts +6 -2
  38. package/lib/types/client/locales.d.ts +34 -2
  39. package/lib/types/client/meta.d.ts +6 -0
  40. package/lib/types/client/service.d.ts +50 -6
  41. package/lib/types/client/slots.d.ts +57 -5
  42. package/lib/types/client/store.d.ts +14 -1
  43. package/lib/types/client/tab.d.ts +31 -0
  44. package/lib/types/index.d.ts +8 -1
  45. package/lib/types/inject.d.ts +150 -0
  46. package/lib/types/store.d.ts +27 -4
  47. package/lib/types/types.d.ts +49 -0
  48. package/lib/types/variables.d.ts +24 -0
  49. package/lib/variables.js +36 -0
  50. package/package.json +98 -105
@@ -1,15 +1,16 @@
1
- /**
2
- * Composer entry button: toggles the quick prompt panel. Registered into
3
- * conversation.input.right (the tool row, before the send button). The
4
- * session-scoped inject face carries the toggle verb, which routes through
5
- * ctx.promptPanel to the panel's store.
6
- */
7
1
  import { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
8
2
  import type { PromptPanelToggleFace } from './slots.ts';
9
3
  /** Full props of the composer entry. */
10
- export type PanelButtonProps = PropsRuntime<'conversation.input.right'> & PromptPanelToggleFace & PropsLocale<'promptTemplates'>;
4
+ export type PanelButtonProps = PropsRuntime<'conversation.input.right'> & PromptPanelToggleFace & PropsLocale<'promptTemplates'> & {
5
+ /**
6
+ * Session identity of this composer (session-scope standard prop,
7
+ * declared locally because the ui-session type augmentation is not in
8
+ * this package's compile-time graph; the runtime always provides it).
9
+ */
10
+ sessionId?: string | undefined;
11
+ };
11
12
  /**
12
13
  * The composer tool-row button.
13
- * @param props - runtime kit (includes the InputZone owner share), the toggle verb, and the locale seat.
14
+ * @param props - runtime kit (the composer's sessionId), the toggle + attach verbs, and the locale seat.
14
15
  */
15
- export declare function PanelButton({ toggle, t }: PanelButtonProps): import("react").JSX.Element;
16
+ export declare function PanelButton({ toggle, attachSession, sessionId, t }: PanelButtonProps): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The prompt-templates right-sidebar tab body: the shared template library
3
+ * mounted into the 'sidebar.right.pane.tab' slot. The slot is
4
+ * session-scoped, so the runtime kit hands the standard sessionId prop
5
+ * directly — the delivery target is whichever session the sidebar is
6
+ * viewing, no composer attachment needed. The tab chrome (icon row entry,
7
+ * selection state) comes from the tab registration in tab.ts.
8
+ */
9
+ import { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
10
+ import type { TemplateLibraryFace } from './slots.ts';
11
+ /** Full props of the sidebar tab body entry. */
12
+ export type PromptTabProps = PropsRuntime<'sidebar.right.pane.tab'> & TemplateLibraryFace & PropsLocale<'promptTemplates'>;
13
+ /**
14
+ * The prompt-templates sidebar tab body.
15
+ * @param props - runtime kit (carries sessionId), injected face members, locale.
16
+ */
17
+ export declare function PromptTab(props: PromptTabProps): import("react").JSX.Element;
@@ -4,7 +4,7 @@
4
4
  * `{ ok: true; value } | { ok: false; error }` envelope the panel face
5
5
  * consumes, so callers never see transport details.
6
6
  */
7
- import type { CategoryView, TemplateView } from '../types.ts';
7
+ import type { CategoryView, InjectionHistoryEntry, InjectionStatusView, TemplateInjectMode, TemplateView } from '../types.ts';
8
8
  /** Business error carried by a failed call. */
9
9
  export interface TemplateError {
10
10
  readonly code: string;
@@ -20,6 +20,10 @@ export type TemplateActionResult = {
20
20
  };
21
21
  /** Load the full template set (global + every session's). */
22
22
  export declare function listTemplates(): Promise<TemplateView[]>;
23
+ /** Poll a session's latest scheduled injection; null when none since boot (badges hide). */
24
+ export declare function injectStatus(sessionId: string): Promise<InjectionStatusView | null>;
25
+ /** Load a session recent scheduled injections, newest first (empty when none). */
26
+ export declare function injectionHistory(sessionId: string): Promise<readonly InjectionHistoryEntry[]>;
23
27
  /** Load every user category tab (global + all sessions'; the panel filters). */
24
28
  export declare function listCategories(): Promise<CategoryView[]>;
25
29
  /** Create one category tab. */
@@ -37,6 +41,9 @@ export declare function createTemplate(request: {
37
41
  scope: 'global' | 'session';
38
42
  session_id: string | null;
39
43
  category?: string | null;
44
+ inject_enabled?: boolean;
45
+ inject_every?: number | null;
46
+ mode?: TemplateInjectMode;
40
47
  }): Promise<TemplateActionResult>;
41
48
  /** Patch one template by id. */
42
49
  export declare function updateTemplate(id: string, request: {
@@ -45,6 +52,9 @@ export declare function updateTemplate(id: string, request: {
45
52
  description?: string | null;
46
53
  position?: number;
47
54
  category?: string | null;
55
+ inject_enabled?: boolean;
56
+ inject_every?: number | null;
57
+ mode?: TemplateInjectMode;
48
58
  }): Promise<TemplateActionResult>;
49
59
  /** Promote one session template to the global partition. */
50
60
  export declare function makeTemplateGlobal(id: string): Promise<TemplateActionResult>;
@@ -0,0 +1,10 @@
1
+ import type { CategoryView, TemplateView } from '../types.ts';
2
+ /**
3
+ * Filter the panel's rows. A non-empty query is global across every category
4
+ * while respecting privacy: every global template and only the current
5
+ * session's private templates are searchable. With no query, the active tab
6
+ * keeps its normal partition/category semantics.
7
+ */
8
+ /** All templates a search is allowed to inspect (global + current session). */
9
+ export declare function searchableTemplateRows(templates: readonly TemplateView[], sessionId: string | null): TemplateView[];
10
+ export declare function filterTemplateRows(templates: readonly TemplateView[], query: string, effectiveTab: string, activeCategory: CategoryView | undefined, sessionId: string | null): TemplateView[];
@@ -11,15 +11,18 @@
11
11
  * namespace (absent when the host exposes no settings document — the panel
12
12
  * then just starts closed).
13
13
  */
14
- import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client';
14
+ import type { Context as ClientContext } from '@deepseek-ai/cordis';
15
15
  import { type IPromptPanel } from './service.ts';
16
16
  import { type PromptTemplateKey } from './locales.ts';
17
17
  export { PromptPanel } from './Panel.tsx';
18
18
  export { PanelButton } from './PanelButton.tsx';
19
+ export { PromptTab } from './PromptTab.tsx';
20
+ export { PROMPT_TEMPLATES_KIND, PROMPT_TEMPLATES_ID, promptTemplatesTabDefinition } from './tab.ts';
19
21
  export { PromptPanelController } from './service.ts';
20
22
  export type { PromptPanelProps } from './Panel.tsx';
21
23
  export type { PanelButtonProps } from './PanelButton.tsx';
22
- export type { PromptPanelFace, PromptPanelToggleFace } from './slots.ts';
24
+ export type { PromptTabProps } from './PromptTab.tsx';
25
+ export type { PromptPanelFace, PromptPanelToggleFace, TemplateLibraryFace } from './slots.ts';
23
26
  export type { IPromptPanel } from './service.ts';
24
27
  declare module '@deepseek-ai/cordis' {
25
28
  interface Context {
@@ -35,6 +38,7 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
35
38
  }
36
39
  /** Required services: slots, sessions, locale, conversation, and settings scope. */
37
40
  export declare const inject: string[];
41
+ /** The promptTemplates settings section (registered host-side; optional). */
38
42
  /**
39
43
  * Client plugin body: the shell.overlay panel owns the store; the controller
40
44
  * bridges its actions to the composer entry and performs inserts.
@@ -7,7 +7,13 @@ export declare const zh: {
7
7
  readonly 'panel.open': "打开提示词面板";
8
8
  readonly 'panel.close': "关闭提示词面板";
9
9
  readonly 'panel.empty': "暂无模板";
10
- readonly 'panel.search': "搜索模板…";
10
+ readonly 'panel.search': "搜索全部模板…";
11
+ readonly 'panel.searchCount': "匹配数 / 可搜索总数";
12
+ readonly 'panel.tabCount': "当前分类模板数";
13
+ readonly 'panel.injectedAt': "定时注入至轮次";
14
+ readonly 'panel.historyTitle': "最近定时注入";
15
+ readonly 'panel.historyEmpty': "本次启动后还没有定时注入";
16
+ readonly 'panel.github': "在 GitHub 查看源码";
11
17
  readonly 'panel.noMatch': "没有匹配的模板";
12
18
  readonly 'panel.global': "全局模板";
13
19
  readonly 'panel.session': "会话模板";
@@ -26,9 +32,19 @@ export declare const zh: {
26
32
  readonly 'panel.delete': "删除";
27
33
  readonly 'panel.edit': "编辑";
28
34
  readonly 'panel.makeGlobal': "设为全局";
35
+ readonly 'panel.inject': "定时注入";
36
+ readonly 'panel.injectEvery': "注入间隔(轮)";
37
+ readonly 'panel.variablesHint': "支持变量:{{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}}(发送/注入时展开,不可得时保留原文)";
38
+ readonly 'panel.modeLabel': "注入呈现方式";
39
+ readonly 'panel.modeInject': "静默注入";
40
+ readonly 'panel.modeVisible': "对话流可见";
41
+ readonly 'panel.modeHint': "静默:只进模型上下文(对话流不显示,基座设计);可见:以用户消息样式显示在对话流中,带\"⚙️ 定时注入\"标记";
29
42
  readonly 'panel.error': "操作失败";
30
43
  readonly 'panel.inserted': "已插入";
31
44
  readonly 'panel.none': "无";
45
+ readonly 'tab.title': "提示词";
46
+ readonly 'tab.guideTitle': "提示词模板";
47
+ readonly 'tab.guideDescription': "模板库:插入、发送、定时注入";
32
48
  };
33
49
  /** English dictionary. */
34
50
  export declare const en: {
@@ -38,7 +54,13 @@ export declare const en: {
38
54
  readonly 'panel.open': "Open prompt panel";
39
55
  readonly 'panel.close': "Close prompt panel";
40
56
  readonly 'panel.empty': "No templates yet";
41
- readonly 'panel.search': "Search templates…";
57
+ readonly 'panel.search': "Search all templates…";
58
+ readonly 'panel.searchCount': "Matches / total searchable";
59
+ readonly 'panel.tabCount': "Templates in current tab";
60
+ readonly 'panel.injectedAt': "Scheduled injection at turn";
61
+ readonly 'panel.historyTitle': "Recent injections";
62
+ readonly 'panel.historyEmpty': "No scheduled injections since boot";
63
+ readonly 'panel.github': "View source on GitHub";
42
64
  readonly 'panel.noMatch': "No matching templates";
43
65
  readonly 'panel.global': "Global templates";
44
66
  readonly 'panel.session': "Session templates";
@@ -57,9 +79,19 @@ export declare const en: {
57
79
  readonly 'panel.delete': "Delete";
58
80
  readonly 'panel.edit': "Edit";
59
81
  readonly 'panel.makeGlobal': "Make global";
82
+ readonly 'panel.inject': "Auto-inject";
83
+ readonly 'panel.injectEvery': "Every (rounds)";
84
+ readonly 'panel.variablesHint': "Variables: {{date}} {{time}} {{datetime}} {{weekday}} {{session}} {{turn}} (expanded at delivery; unresolved stay literal)";
85
+ readonly 'panel.modeLabel': "Injection delivery";
86
+ readonly 'panel.modeInject': "Silent (model-only)";
87
+ readonly 'panel.modeVisible': "Visible in chat";
88
+ readonly 'panel.modeHint': "Silent: model context only (omitted from the chat transcript by base design); Visible: rendered as a user message in the chat flow, headed by a ⚙️ scheduled-injection marker";
60
89
  readonly 'panel.error': "Operation failed";
61
90
  readonly 'panel.inserted': "Inserted";
62
91
  readonly 'panel.none': "None";
92
+ readonly 'tab.title': "Prompts";
93
+ readonly 'tab.guideTitle': "Prompt templates";
94
+ readonly 'tab.guideDescription': "Template library: insert, send, auto-inject";
63
95
  };
64
96
  /** Key union of the prompt-templates dictionary. */
65
97
  export type PromptTemplateKey = keyof typeof zh;
@@ -0,0 +1,6 @@
1
+ /** Canonical public source repository for the panel's metadata link. */
2
+ export declare const GITHUB_REPOSITORY_URL = "https://github.com/NelsonLongXiang/dsh-prompt-templates";
3
+ /** Build-injected package version; `dev` only exists in unbundled unit tests. */
4
+ export declare const PLUGIN_VERSION: string;
5
+ /** Header count: current-tab size when idle, matched/searchable when searching. */
6
+ export declare function templateCountLabel(matched: number, searchable: number, searching: boolean): string;
@@ -8,14 +8,41 @@
8
8
  * as the registration's bound actions.
9
9
  */
10
10
  import type { BoundActions } from '@deepseek-ai/dsh-client-ui-slots';
11
- import type { ClientContext, SessionId, ISessions } from '@deepseek-ai/dsh-client-runtime/client';
11
+ import type { Context as ClientContext } from '@deepseek-ai/cordis';
12
+ import type { SessionId } from '@deepseek-ai/dsh-session/types';
13
+ import type { ISessions } from '@deepseek-ai/dsh-api-session-controller/client';
12
14
  import type { createPromptPanelStore } from './store.ts';
15
+ /**
16
+ * The live insertion span the input face hands out: a [start, end) range in
17
+ * the draft's text coordinates plus the draft revision it was captured
18
+ * against. A stale revision (or a locked admission transaction) makes
19
+ * `insertText` decline instead of applying at the wrong place.
20
+ */
21
+ export interface InsertionSpan {
22
+ start: number;
23
+ end: number;
24
+ draftRev: number;
25
+ }
13
26
  /** The panel store's bound action set (framework-baked, draft params peeled). */
14
27
  export type PromptPanelActions = BoundActions<ReturnType<typeof createPromptPanelStore>>;
15
28
  /** The outward prompt-panel face (`ctx.promptPanel`). */
16
29
  export interface IPromptPanel {
17
30
  /** Flip the panel open/closed. */
18
31
  toggle(): void;
32
+ /**
33
+ * Record the session whose composer entry was clicked — the panel's
34
+ * delivery target for insert/send/interject and session-scoped templates.
35
+ * The session-scoped composer entry calls this at click time, replacing
36
+ * the pre-0.2.0 `SessionListState.current` lookup (the 0.2.0 session list
37
+ * has no selection field; `ids[0]` is merely the newest list row).
38
+ */
39
+ setTargetSession(sessionId: SessionId): void;
40
+ /** The delivery target: the composer that last opened the panel. */
41
+ targetSession(): SessionId | undefined;
42
+ /** Monotonic counter bumping on every target change (useSyncExternalStore snapshot). */
43
+ targetVersion(): number;
44
+ /** Delivery-target change subscription (drives the open panel's re-render). */
45
+ subscribeTarget(notify: () => void): () => void;
19
46
  /** Insert one template's content into a session's composer draft at the caret. */
20
47
  insert(sessionId: SessionId, content: string): void;
21
48
  /** Submit one template's content immediately, preserving the user's draft. */
@@ -51,6 +78,21 @@ export declare class PromptPanelController implements IPromptPanel {
51
78
  }): void;
52
79
  /** Flip the panel open/closed. */
53
80
  toggle(): void;
81
+ /**
82
+ * Record the panel's delivery target. Called by the session-scoped
83
+ * composer entry when its session becomes the visible one (mount or
84
+ * session change) and again at click time, so the target always follows
85
+ * the conversation the user is looking at — switching sessions must not
86
+ * leave the panel pointed at a detached composer whose scope (and
87
+ * send/insert path) has gone away.
88
+ */
89
+ setTargetSession(sessionId: SessionId): void;
90
+ /** The session whose composer last opened the panel, if any. */
91
+ targetSession(): SessionId | undefined;
92
+ /** Monotonic change counter of the delivery target (snapshot for useSyncExternalStore). */
93
+ targetVersion(): number;
94
+ /** Subscribe to delivery-target changes; returns the unsubscribe function. */
95
+ subscribeTarget(notify: () => void): () => void;
54
96
  /**
55
97
  * Apply the settings-driven default open, at most once per store lifetime
56
98
  * and never after any user interaction with the panel. Before the entry's
@@ -60,11 +102,13 @@ export declare class PromptPanelController implements IPromptPanel {
60
102
  /**
61
103
  * Insert one template's content into a session's composer draft at the
62
104
  * live caret position (selection, when a range is selected, is replaced).
63
- * The caret lives only in the DOM textarea — the input machine publishes
64
- * no caret — so the composer textarea is located by matching its value
65
- * against the draft snapshot; when no textarea is found the content falls
66
- * back to an end-append (empty draft takes it verbatim, non-empty joins
67
- * with a newline).
105
+ * The caret path goes through the input face's provide-channel pair —
106
+ * capture the caret span with its draft revision, then apply through the
107
+ * face so the editor lands it as one undoable edit. The pair declines on
108
+ * a stale revision or a locked admission transaction (submitting /
109
+ * adjudicating), and older runtimes without the channel simply lack the
110
+ * member; both fall back to an end-append over the draft snapshot (empty
111
+ * draft takes the content verbatim, non-empty joins with a newline).
68
112
  * @param sessionId - target session.
69
113
  * @param content - template content.
70
114
  */
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * Injected faces of the prompt-templates entries. The panel slot
3
3
  * ('shell.overlay') is root-scoped, so its inject factory receives no
4
- * session id — the component reads the current session through the standard
5
- * kit. The composer entry ('conversation.input.right') is session-scoped and
6
- * carries the panel toggle.
4
+ * session id — the delivery target arrives from the composer entry: the
5
+ * session-scoped 'conversation.input.right' button reports its sessionId
6
+ * whenever its composer becomes the visible one (mount, session change,
7
+ * and click), and the panel reads it back through the face. The composer
8
+ * entry carries the panel toggle plus that target attachment.
7
9
  */
8
10
  import type { TemplateActionResult } from './api.ts';
9
- import type { CategoryView, TemplateView } from '../types.ts';
11
+ import type { CategoryView, InjectionHistoryEntry, InjectionStatusView, TemplateInjectMode, TemplateView } from '../types.ts';
10
12
  /** One template row the panel renders (the backend record). */
11
13
  export type { TemplateView };
12
14
  export type { TemplateActionResult, CategoryView };
@@ -36,14 +38,20 @@ export interface PromptPanelFace {
36
38
  scope: 'global' | 'session';
37
39
  session_id: string | null;
38
40
  category?: string | null;
41
+ inject_enabled?: boolean;
42
+ inject_every?: number | null;
43
+ mode?: TemplateInjectMode;
39
44
  }) => Promise<TemplateActionResult>;
40
- /** Patch one template by id (name/content/description/position/category). */
45
+ /** Patch one template by id (name/content/description/position/category/inject facts). */
41
46
  update: (id: string, request: {
42
47
  name?: string;
43
48
  content?: string;
44
49
  description?: string | null;
45
50
  position?: number;
46
51
  category?: string | null;
52
+ inject_enabled?: boolean;
53
+ inject_every?: number | null;
54
+ mode?: TemplateInjectMode;
47
55
  }) => Promise<TemplateActionResult>;
48
56
  /** Delete one template by id. */
49
57
  remove: (id: string) => Promise<TemplateActionResult>;
@@ -61,9 +69,53 @@ export interface PromptPanelFace {
61
69
  send: (sessionId: string, content: string) => void;
62
70
  /** Submit the content immediately while preserving the user's draft (interject). */
63
71
  interject: (sessionId: string, content: string) => void;
72
+ /**
73
+ * The session whose composer entry opened the panel — the delivery target
74
+ * for insert/send/interject and the scope of session-scoped templates.
75
+ * Null before any composer has attached (session tabs stay disabled).
76
+ */
77
+ targetSession: () => string | null;
78
+ /**
79
+ * Monotonic counter that bumps on every target change — the snapshot for
80
+ * useSyncExternalStore. The open panel subscribes so a session switch
81
+ * re-renders it with the fresh target (otherwise its handlers keep the
82
+ * previous render's sessionId closure and send lands nowhere).
83
+ */
84
+ targetVersion: () => number;
85
+ /** Delivery-target change subscription; returns the unsubscribe function. */
86
+ subscribeTarget: (notify: () => void) => () => void;
87
+ /**
88
+ * Poll the attached session's latest scheduled injection (null when none
89
+ * since boot). Feeds the toolbar badge `⟳N`; deliberately a face verb so
90
+ * both surfaces (overlay + tab) share one implementation.
91
+ */
92
+ injectStatus: (sessionId: string) => Promise<InjectionStatusView | null>;
93
+ /**
94
+ * The attached session recent scheduled injections, newest first (bounded
95
+ * server-side). Feeds the badge history dropdown; fetched on demand so
96
+ * the 30s badge poll stays O(1).
97
+ */
98
+ injectionHistory: (sessionId: string) => Promise<readonly InjectionHistoryEntry[]>;
64
99
  }
65
100
  /** The composer entry's injected face: toggle the panel. */
66
101
  export interface PromptPanelToggleFace {
67
102
  /** Flip the panel open/closed. */
68
103
  toggle: () => void;
104
+ /**
105
+ * Attach the panel to one composer's session. The session-scoped button
106
+ * calls this with its standard-kit sessionId prop whenever its composer
107
+ * becomes the visible one — on mount, on session change, and again at
108
+ * click time — so the delivery target follows the conversation the user
109
+ * is looking at instead of freezing on the session that happened to
110
+ * click first.
111
+ */
112
+ attachSession: (sessionId: string) => void;
69
113
  }
114
+ /**
115
+ * The library verbs shared by both surfaces — the floating panel and the
116
+ * right-sidebar tab body: the panel face minus the overlay-only placement
117
+ * knobs and the overlay's target attachment. Each surface resolves its own
118
+ * delivery target (the overlay reads the composer attachment, the tab reads
119
+ * its standard session-scoped props) and hands the library this face.
120
+ */
121
+ export type TemplateLibraryFace = Pick<PromptPanelFace, 'refresh' | 'refreshCategories' | 'createCategory' | 'removeCategory' | 'create' | 'update' | 'remove' | 'makeGlobal' | 'insert' | 'send' | 'interject' | 'injectStatus' | 'injectionHistory'>;
@@ -10,7 +10,7 @@
10
10
  * Module level exports the factory only (de-facto singleton prohibition —
11
11
  * see ui-layout's store).
12
12
  */
13
- import { type EngineStoreHandle } from '@deepseek-ai/dsh-client-runtime/client';
13
+ import { type EngineStoreHandle } from '@deepseek-ai/dsh-client-store';
14
14
  /** Panel state: open flag plus the one-shot default-open marker. */
15
15
  type PromptPanelState = {
16
16
  open: boolean;
@@ -28,4 +28,17 @@ export type PromptPanelActions = {
28
28
  close: (draft: PromptPanelState) => void;
29
29
  openOnce: (draft: PromptPanelState) => void;
30
30
  };
31
+ /** Persisted panel preferences (position + remembered default-open). */
32
+ interface PromptPanelPrefs {
33
+ defaultOpen: boolean;
34
+ panel: {
35
+ x: number;
36
+ y: number;
37
+ } | null;
38
+ }
39
+ /** Complete write set for the persisted preferences. */
40
+ export declare function createPromptPanelPrefsStore(): EngineStoreHandle<PromptPanelPrefs, {
41
+ setPosition: (d: PromptPanelPrefs, x: number, y: number) => void;
42
+ resetPosition: (d: PromptPanelPrefs) => void;
43
+ }>;
31
44
  export {};
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Stage one of the prompt-templates sidebar tab: what the type IS.
3
+ *
4
+ * A page type — it claims no address (no `patterns`): it opens by kind via
5
+ * the guide page's entry box or the tab strip's '+' picker. Stage two (the
6
+ * keyed 'sidebar.right.pane.tab' body registration) lives in
7
+ * client/index.ts and lands the PromptTab component under the same `id`.
8
+ *
9
+ * Pure data with a type-only dependency on the sidebar package, so this
10
+ * module carries zero runtime imports and unit tests load it bare.
11
+ */
12
+ import type { SidebarRightTabDefinition } from '@deepseek-ai/dsh-client-ui-sidebar-right/client';
13
+ /** The tab kind this plugin owns — the name openTab and the guide dispatch by. */
14
+ export declare const PROMPT_TEMPLATES_KIND = "promptTemplates";
15
+ /**
16
+ * This implementation's identity in the tab system, and the key its body
17
+ * registers under in the 'sidebar.right.pane.tab' seat (a package name is
18
+ * the natural value, exactly as the builtin files tab does).
19
+ */
20
+ export declare const PROMPT_TEMPLATES_ID = "@nelsonlongxiang/dsh-prompt-templates";
21
+ /** The dictionary keys this definition reads (narrow union so the locale
22
+ * plugin's namespace-bound translate is assignable — its parameter is the
23
+ * full PromptTemplateKey union, contravariantly compatible with this one). */
24
+ export type PromptTabLocaleKey = 'tab.title' | 'tab.guideTitle' | 'tab.guideDescription';
25
+ /**
26
+ * The prompt-templates type's registry definition.
27
+ * @param t - namespace-bound translate, read fresh on every label call
28
+ * (a language change needs no re-registration).
29
+ * @returns the definition to register.
30
+ */
31
+ export declare function promptTemplatesTabDefinition(t: (key: PromptTabLocaleKey) => string): SidebarRightTabDefinition;
@@ -3,7 +3,9 @@
3
3
  * `node:sqlite` (same schema and database file as the former Python
4
4
  * backend child) exposed over web-server routes the browser panel fetches
5
5
  * (`/plugins/dsh-prompt-templates/*`). The plugin owns the store, the
6
- * routes, and the settings namespace (panel default-open + placement).
6
+ * routes, the settings namespace (panel default-open + placement), and the
7
+ * scheduled auto-injection listener that re-surfaces inject-enabled
8
+ * templates every N rounds.
7
9
  *
8
10
  * Route map (JSON bodies, `Cache-Control: no-store`):
9
11
  * GET /plugins/dsh-prompt-templates/templates → { items }
@@ -12,6 +14,7 @@
12
14
  * PATCH /plugins/dsh-prompt-templates/templates/:id → { template } | 404
13
15
  * POST /plugins/dsh-prompt-templates/templates/:id/make-global → { template } | 404
14
16
  * DELETE /plugins/dsh-prompt-templates/templates/:id → { deleted }
17
+ * GET /plugins/dsh-prompt-templates/inject-status?session_id=… → { status, history }
15
18
  *
16
19
  * @module dsh-prompt-templates
17
20
  */
@@ -23,6 +26,10 @@ export declare const name = "prompt-templates";
23
26
  export interface Config {
24
27
  /** Optional explicit SQLite database path; defaults to `$DSH_HOME/ext/prompt-templates/db.sqlite3`. */
25
28
  readonly dbPath?: string | null;
29
+ /** Scheduled-injection master switch; `false` keeps the listener pass-through. */
30
+ readonly injectEnabled?: boolean;
31
+ /** Upper bound accepted for a template's inject interval (`inject_every`). */
32
+ readonly injectMaxEvery?: number;
26
33
  }
27
34
  export declare const Config: s<Config>;
28
35
  /** Business error envelope shared with the browser face. */
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Scheduled template auto-injection (host half): re-surfaces inject-enabled
3
+ * templates into the model context on turn boundaries. The single sanctioned
4
+ * mutation point is the `agent/pre-step` waterfall — its enter decision can
5
+ * append user-role messages, which the loop then logs as durable
6
+ * `user/message` events, keeping the model-visible input replayable. The
7
+ * `<system-reminder>` frame and typed source mirror the tool-skill catalog
8
+ * precedent.
9
+ *
10
+ * Trigger semantics: a template injects at the FIRST admitted step of every
11
+ * boundary turn (`turn % inject_every === 0`, turns are 1-based and durable).
12
+ * Idempotence is anchored on the durable log — a boundary turn that already
13
+ * carries a `prompt-template-schedule` message is never injected twice —
14
+ * while a per-session in-memory memo keeps the common step free of scans.
15
+ *
16
+ * @module dsh-prompt-templates/inject
17
+ */
18
+ import type { Context } from '@deepseek-ai/cordis';
19
+ import type { UserMessage } from '@deepseek-ai/dsh-session';
20
+ import type { TemplateStore } from './store.ts';
21
+ import type { InjectionHistoryEntry, InjectionStatusView, TemplateInjectMode, TemplateView } from './types.ts';
22
+ /**
23
+ * Durable provenance for one scheduled injection, recorded beside the
24
+ * model-facing prose so non-model consumers (audit, replay) never re-parse
25
+ * the `<system-reminder>` framing.
26
+ */
27
+ export interface TemplateScheduleSource {
28
+ readonly kind: 'prompt-template-schedule';
29
+ /** The boundary turn this message belongs to. */
30
+ readonly turn: number;
31
+ /** Exactly the templates this message injected, in injection order. */
32
+ readonly templates: readonly {
33
+ readonly id: string;
34
+ readonly name: string;
35
+ readonly every: number;
36
+ }[];
37
+ }
38
+ declare module '@deepseek-ai/dsh-llm' {
39
+ interface MessageSourceMap {
40
+ 'prompt-template-schedule': TemplateScheduleSource;
41
+ }
42
+ }
43
+ /** One inject-enabled template due at a boundary turn. */
44
+ export interface InjectCandidate {
45
+ readonly id: string;
46
+ readonly name: string;
47
+ readonly content: string;
48
+ readonly every: number;
49
+ /** Delivery mode: `visible` renders in the chat transcript (user channel). */
50
+ readonly mode: TemplateInjectMode;
51
+ }
52
+ /** Structural slice of a durable session event the idempotence probe reads. */
53
+ export interface InjectionEventProbe {
54
+ readonly type: string;
55
+ readonly data: {
56
+ readonly source?: unknown;
57
+ };
58
+ }
59
+ /** Deployment-facing switch; the listener stays registered but pass-through when off. */
60
+ export interface AutoInjectConfig {
61
+ readonly enabled: boolean;
62
+ }
63
+ /**
64
+ * Client-facing summary of a session's latest scheduled injection, polled by
65
+ * the panel/tab toolbar badge (`⟳N`). Defined in types.ts (client-safe) and
66
+ * re-exported here so the host half reads one name.
67
+ */
68
+ export type { InjectionStatusView } from './types.ts';
69
+ /** How many recent injections per session the history surface keeps. */
70
+ export declare const INJECTION_HISTORY_LIMIT = 20;
71
+ /**
72
+ * Per-session injection bookkeeping. Memory-only surface for the UI badge
73
+ * and its history dropdown; correctness of injection itself never depends
74
+ * on it (the durable log remains the idempotence anchor).
75
+ */
76
+ export declare class InjectionTracker {
77
+ #private;
78
+ /** Record that `sessionId` just received the injection described by `entry`. */
79
+ note(sessionId: string, entry: InjectionHistoryEntry): void;
80
+ /** The latest injection recorded for `sessionId`, or null if none since boot. */
81
+ status(sessionId: string): InjectionStatusView | null;
82
+ /** The session recent injections, newest first (bounded by INJECTION_HISTORY_LIMIT). */
83
+ history(sessionId: string): readonly InjectionHistoryEntry[];
84
+ }
85
+ /** What `registerAutoInject` hands back: the UI status and history surfaces. */
86
+ export interface AutoInjectHandle {
87
+ readonly status: (sessionId: string) => InjectionStatusView | null;
88
+ readonly history: (sessionId: string) => readonly InjectionHistoryEntry[];
89
+ }
90
+ /** Whether `turn` is a boundary turn for the interval `every` (both 1-based positive). */
91
+ export declare function isBoundaryTurn(turn: number, every: number): boolean;
92
+ /** Narrow one page of templates to those enabled and due at this boundary turn, preserving store order. */
93
+ export declare function dueTemplates(templates: readonly TemplateView[], turn: number): InjectCandidate[];
94
+ /**
95
+ * Whether the event window `[scannedFrom, events.length)` already carries a
96
+ * scheduled injection for `turn`. Backward scan over durable events only —
97
+ * the same posture as the skill-catalog probe, so compaction visibility and
98
+ * restart resume never resurrect a duplicate. Matches BOTH delivery shapes:
99
+ * the silent `prompt-template-schedule` source and the visible user-channel
100
+ * source (`kind:'user'` + `scheduled:'prompt-template'`).
101
+ */
102
+ export declare function alreadyInjectedAtTurn(events: readonly InjectionEventProbe[], scannedFrom: number, turn: number): boolean;
103
+ /**
104
+ * Render ONE combined `<system-reminder>` user message for the due
105
+ * templates. The frame is written for the model (English, like every
106
+ * first-party reminder); template content is embedded verbatim and the
107
+ * durable source records what went out.
108
+ */
109
+ export declare function renderInjectionMessage(turn: number, templates: readonly InjectCandidate[]): UserMessage;
110
+ /**
111
+ * Durable provenance for a VISIBLE scheduled injection (user channel): the
112
+ * chat view renders `kind !== 'user'` sources as omitted context rows, so a
113
+ * visible injection stamps the user kind and disambiguates itself with the
114
+ * `scheduled` marker — keeping the dedup scan working (the marker, not the
115
+ * kind, carries the schedule identity).
116
+ */
117
+ export interface VisibleScheduleSource {
118
+ readonly kind: 'user';
119
+ readonly scheduled: 'prompt-template';
120
+ /** The boundary turn this message belongs to. */
121
+ readonly turn: number;
122
+ /** Exactly the templates this message injected, in injection order. */
123
+ readonly templates: readonly {
124
+ readonly id: string;
125
+ readonly name: string;
126
+ readonly every: number;
127
+ }[];
128
+ }
129
+ /**
130
+ * Render ONE visible scheduled injection as an ordinary user message. The
131
+ * header names the origin (so a reader never mistakes it for human typing)
132
+ * and the durable source keeps the dedup-scan marker.
133
+ */
134
+ export declare function renderVisibleInjectionMessage(turn: number, templates: readonly InjectCandidate[]): UserMessage;
135
+ /**
136
+ * Register the `agent/pre-step` listener that performs scheduled injection
137
+ * for every agent in this composition. Registration order is irrelevant:
138
+ * the listener calls `next()` first and only appends to the downstream
139
+ * decision, so other pre-step listeners keep their own semantics.
140
+ *
141
+ * Failure posture mirrors the skill catalog: a fault inside this listener
142
+ * must never fail the session's steps, so the first fault is reported and
143
+ * later ones stay silent while injection degrades to pass-through.
144
+ *
145
+ * @param ctx - host context to attach the listener to.
146
+ * @param config - deployment switch.
147
+ * @param store - lazy template store accessor (shared with the routes).
148
+ * @returns handle exposing the per-session last-injection status for the UI.
149
+ */
150
+ export declare function registerAutoInject(ctx: Context, config: AutoInjectConfig, store: () => TemplateStore): AutoInjectHandle;