@klarkxy/dsh-current-title 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.
@@ -0,0 +1,43 @@
1
+ //#region src/contracts.ts
2
+ const PLUGIN_NAME = "@klarkxy/dsh-current-title";
3
+ const FEATURE_ID = "current-title";
4
+ const PROVIDER_ID = "@klarkxy/dsh-current-title";
5
+ const PURPOSE_ID = "current-title.generate";
6
+ const RPC_CHANNEL = "/dsh-current-title";
7
+ const TITLE_CLIENT_SERVICE = "dshCurrentTitleClient";
8
+ const PROMPT_VERSION = "current-title.v1";
9
+ const SCHEMA_VERSION = "title-json.v1";
10
+ const CONTRACT_VERSION = 1;
11
+ const SETTINGS_KEY = "current";
12
+ const DEFAULT_MAX_RECENT_MESSAGES = 8;
13
+ const DEFAULT_TARGET_WORDS = 5;
14
+ const DEFAULT_TARGET_CJK = 10;
15
+ const DEFAULT_MAX_INPUT_BYTES = 4096;
16
+ const DEFAULT_MAX_OUTPUT_TOKENS = 64;
17
+ const DEFAULT_TIMEOUT_MS = 6e4;
18
+ const DEFAULT_MAX_TITLE_BYTES = 80;
19
+ function defaultSettings(locale = "auto") {
20
+ return {
21
+ revision: 0,
22
+ locale
23
+ };
24
+ }
25
+ function defaultGenerateConfig(locale = "auto") {
26
+ return {
27
+ maxRecentMessages: 8,
28
+ locale,
29
+ targetWords: 5,
30
+ targetCjkCharacters: 10,
31
+ maxInputBytes: DEFAULT_MAX_INPUT_BYTES,
32
+ maxOutputTokens: 64,
33
+ timeoutMs: DEFAULT_TIMEOUT_MS,
34
+ maxTitleBytes: 80
35
+ };
36
+ }
37
+ function isTitleLocaleMode(value) {
38
+ return value === "auto" || value === "zh" || value === "en";
39
+ }
40
+ //#endregion
41
+ export { CONTRACT_VERSION, DEFAULT_MAX_INPUT_BYTES, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_MAX_RECENT_MESSAGES, DEFAULT_MAX_TITLE_BYTES, DEFAULT_TARGET_CJK, DEFAULT_TARGET_WORDS, DEFAULT_TIMEOUT_MS, FEATURE_ID, PLUGIN_NAME, PROMPT_VERSION, PROVIDER_ID, PURPOSE_ID, RPC_CHANNEL, SCHEMA_VERSION, SETTINGS_KEY, TITLE_CLIENT_SERVICE, defaultGenerateConfig, defaultSettings, isTitleLocaleMode };
42
+
43
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","names":[],"sources":["../src/contracts.ts"],"sourcesContent":["/** Browser-safe contracts. Shared RPC/result types stay on @klarkxy/dsh-ai-services. */\nexport type { RpcResult } from '@klarkxy/dsh-ai-services/contracts'\n\nexport const PLUGIN_NAME = '@klarkxy/dsh-current-title'\nexport const FEATURE_ID = 'current-title'\nexport const PROVIDER_ID = '@klarkxy/dsh-current-title'\nexport const PURPOSE_ID = 'current-title.generate'\nexport const RPC_CHANNEL = '/dsh-current-title'\nexport const TITLE_CLIENT_SERVICE = 'dshCurrentTitleClient'\nexport const PROMPT_VERSION = 'current-title.v1'\nexport const SCHEMA_VERSION = 'title-json.v1'\nexport const CONTRACT_VERSION = 1\nexport const SETTINGS_KEY = 'current'\n\nexport const DEFAULT_MAX_RECENT_MESSAGES = 8\nexport const DEFAULT_TARGET_WORDS = 5\nexport const DEFAULT_TARGET_CJK = 10\nexport const DEFAULT_MAX_INPUT_BYTES = 4096\nexport const DEFAULT_MAX_OUTPUT_TOKENS = 64\nexport const DEFAULT_TIMEOUT_MS = 60_000\nexport const DEFAULT_MAX_TITLE_BYTES = 80\n\nexport type TitleLocaleMode = 'auto' | 'zh' | 'en'\nexport type TitleSourceKind = 'fallback' | 'provider' | 'user'\n\nexport interface TitleMessage {\n readonly seq: number\n readonly text: string\n}\n\nexport interface TitleSnapshot {\n readonly title: string\n readonly messageSeqs: readonly number[]\n readonly source: { readonly kind: TitleSourceKind; readonly provider?: string }\n readonly eventSeq: number\n readonly updatedAt: number\n}\n\nexport interface TitleSettings {\n revision: number\n locale: TitleLocaleMode\n}\n\nexport interface TitleSupport {\n nativeOwner: string | null\n weOwn: boolean\n limitation?: string\n}\n\nexport interface TitleStatus {\n settings: TitleSettings\n support: TitleSupport\n session?: {\n sessionId: string\n title?: string\n sourceKind?: TitleSourceKind\n generating: boolean\n pinned: boolean\n }\n}\n\nexport interface TitleClientMarker {\n active: boolean\n}\n\nexport interface GenerateConfig {\n readonly maxRecentMessages: number\n readonly locale: TitleLocaleMode\n readonly targetWords: number\n readonly targetCjkCharacters: number\n readonly maxInputBytes: number\n readonly maxOutputTokens: number\n readonly timeoutMs: number\n readonly maxTitleBytes: number\n}\n\nexport function defaultSettings(locale: TitleLocaleMode = 'auto'): TitleSettings {\n return { revision: 0, locale }\n}\n\nexport function defaultGenerateConfig(locale: TitleLocaleMode = 'auto'): GenerateConfig {\n return {\n maxRecentMessages: DEFAULT_MAX_RECENT_MESSAGES,\n locale,\n targetWords: DEFAULT_TARGET_WORDS,\n targetCjkCharacters: DEFAULT_TARGET_CJK,\n maxInputBytes: DEFAULT_MAX_INPUT_BYTES,\n maxOutputTokens: DEFAULT_MAX_OUTPUT_TOKENS,\n timeoutMs: DEFAULT_TIMEOUT_MS,\n maxTitleBytes: DEFAULT_MAX_TITLE_BYTES,\n }\n}\n\nexport function isTitleLocaleMode(value: unknown): value is TitleLocaleMode {\n return value === 'auto' || value === 'zh' || value === 'en'\n}\n"],"mappings":";AAGA,MAAa,cAAc;AAC3B,MAAa,aAAa;AAC1B,MAAa,cAAc;AAC3B,MAAa,aAAa;AAC1B,MAAa,cAAc;AAC3B,MAAa,uBAAuB;AACpC,MAAa,iBAAiB;AAC9B,MAAa,iBAAiB;AAC9B,MAAa,mBAAmB;AAChC,MAAa,eAAe;AAE5B,MAAa,8BAA8B;AAC3C,MAAa,uBAAuB;AACpC,MAAa,qBAAqB;AAClC,MAAa,0BAA0B;AACvC,MAAa,4BAA4B;AACzC,MAAa,qBAAqB;AAClC,MAAa,0BAA0B;AAwDvC,SAAgB,gBAAgB,SAA0B,QAAuB;CAC/E,OAAO;EAAE,UAAU;EAAG;CAAO;AAC/B;AAEA,SAAgB,sBAAsB,SAA0B,QAAwB;CACtF,OAAO;EACL,mBAAA;EACA;EACA,aAAA;EACA,qBAAA;EACA,eAAe;EACf,iBAAA;EACA,WAAW;EACX,eAAA;CACF;AACF;AAEA,SAAgB,kBAAkB,OAA0C;CAC1E,OAAO,UAAU,UAAU,UAAU,QAAQ,UAAU;AACzD"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,160 @@
1
+ import { TitleLocaleMode as TitleLocaleMode$1, TitleMessage, TitleSettings, TitleSnapshot, TitleStatus, TitleSupport } from "./contracts.js";
2
+ import { AiServices } from "@klarkxy/dsh-ai-services/contracts";
3
+ import { Context } from "@deepseek-ai/cordis";
4
+ //#region src/messages.d.ts
5
+ interface SessionEventLike {
6
+ readonly type: string;
7
+ readonly seq: number;
8
+ readonly time?: number;
9
+ readonly data?: {
10
+ readonly source?: {
11
+ readonly kind?: string;
12
+ readonly plugin?: string;
13
+ readonly provider?: string;
14
+ };
15
+ readonly content?: ReadonlyArray<{
16
+ readonly type?: string;
17
+ readonly text?: string;
18
+ }>;
19
+ readonly title?: string;
20
+ readonly messageSeqs?: readonly number[];
21
+ };
22
+ }
23
+ interface SessionLike {
24
+ readonly id: string;
25
+ readonly seq?: number;
26
+ snapshotEvents(): readonly SessionEventLike[];
27
+ append?(type: string, data: unknown): unknown;
28
+ }
29
+ //#endregion
30
+ //#region src/native-slot.d.ts
31
+ interface SessionTitleProvider {
32
+ readonly id: string;
33
+ readonly automatic: 'first-prompt' | 'all-prompts';
34
+ generate(request: {
35
+ session: {
36
+ id: string;
37
+ snapshotEvents(): readonly unknown[];
38
+ };
39
+ messages: ReadonlyArray<{
40
+ seq: number;
41
+ text: string;
42
+ }>;
43
+ route?: {
44
+ provider: string;
45
+ model: string;
46
+ };
47
+ signal: AbortSignal;
48
+ }): Promise<{
49
+ title: string;
50
+ messageSeqs: readonly number[];
51
+ model?: {
52
+ provider: string;
53
+ model: string;
54
+ };
55
+ }>;
56
+ }
57
+ interface SessionTitleServiceLike {
58
+ register(provider: SessionTitleProvider): () => void | Promise<void>;
59
+ get(session: unknown): {
60
+ title: string;
61
+ source?: {
62
+ kind?: string;
63
+ provider?: string;
64
+ };
65
+ eventSeq?: number;
66
+ updatedAt?: number;
67
+ messageSeqs?: readonly number[];
68
+ } | undefined;
69
+ refresh(session: unknown, signal?: AbortSignal): Promise<unknown>;
70
+ }
71
+ interface LoaderEntryOptions {
72
+ id?: string;
73
+ name?: string;
74
+ disabled?: boolean | null;
75
+ config?: unknown;
76
+ inject?: unknown;
77
+ group?: boolean | null;
78
+ }
79
+ interface LoaderEntry {
80
+ id: string;
81
+ options?: LoaderEntryOptions;
82
+ }
83
+ interface LoaderFace {
84
+ entries(): Iterable<LoaderEntry>;
85
+ update(id: string, options: {
86
+ disabled?: boolean | null;
87
+ }): Promise<unknown> | unknown;
88
+ }
89
+ //#endregion
90
+ //#region src/output.d.ts
91
+ declare const TITLE_TYPE_KEYS: readonly ["feature", "fix", "optimize", "refactor", "test", "docs", "release", "config", "explore", "discuss"];
92
+ declare const TITLE_LOCALES: readonly ["zh", "en"];
93
+ declare const TITLE_LOCALE_MODES: readonly ["auto", "zh", "en"];
94
+ type TitleType = (typeof TITLE_TYPE_KEYS)[number];
95
+ type TitleLocale = (typeof TITLE_LOCALES)[number];
96
+ type TitleLocaleMode = (typeof TITLE_LOCALE_MODES)[number];
97
+ interface ParsedTitle {
98
+ type: TitleType;
99
+ summary: string;
100
+ }
101
+ declare function resolveTitleLocale(mode: TitleLocaleMode, messages: readonly string[], preference?: string): TitleLocale;
102
+ declare function parseModelTitle(raw: string, targetWords: number, targetCjkCharacters: number): ParsedTitle;
103
+ declare function formatTitle(parsed: ParsedTitle, locale: TitleLocale, now?: Date): string;
104
+ //#endregion
105
+ //#region src/service.d.ts
106
+ interface TitleSettingsStore {
107
+ load(): TitleSettings | undefined;
108
+ save(settings: TitleSettings): Promise<void>;
109
+ }
110
+ declare class CurrentTitleService {
111
+ private readonly options;
112
+ private settings;
113
+ private config;
114
+ private scope?;
115
+ private unregisterPurpose?;
116
+ private claim?;
117
+ private nativeSlot?;
118
+ private generation;
119
+ private readonly inFlight;
120
+ readonly support: TitleSupport;
121
+ constructor(options: {
122
+ plugin: string;
123
+ ai?: AiServices;
124
+ sessionTitle?: SessionTitleServiceLike;
125
+ loader?: LoaderFace;
126
+ sessions?: {
127
+ get(id: string): SessionLike | undefined;
128
+ };
129
+ store?: TitleSettingsStore;
130
+ localePreference?: () => string | undefined;
131
+ initialLocale?: TitleLocaleMode;
132
+ now?: () => Date;
133
+ });
134
+ start(): Promise<void>;
135
+ dispose(): Promise<void>;
136
+ status(sessionId?: string): TitleStatus;
137
+ updateLocale(locale: TitleLocaleMode, expectedRevision: number): Promise<TitleSettings>;
138
+ regenerate(sessionId: string, signal: AbortSignal): Promise<TitleSnapshot | undefined>;
139
+ read(session: SessionLike): TitleSnapshot | undefined;
140
+ private nativeGenerate;
141
+ }
142
+ //#endregion
143
+ //#region src/input.d.ts
144
+ declare function frameMessages(messages: readonly TitleMessage[]): string;
145
+ declare function selectRecentMessages(messages: readonly TitleMessage[], maxRecentMessages: number, maxInputBytes: number): TitleMessage[];
146
+ //#endregion
147
+ //#region src/index.d.ts
148
+ declare const name = "@klarkxy/dsh-current-title";
149
+ declare const inject: readonly ["sessionTitle", "aiServices", "sessions", "loader", "storageDomain", "connection", "webServer"];
150
+ declare module '@deepseek-ai/cordis' {
151
+ interface Context {
152
+ currentTitle: CurrentTitleService;
153
+ }
154
+ }
155
+ declare function apply(ctx: Context, config?: {
156
+ locale?: TitleLocaleMode$1;
157
+ }): Promise<void>;
158
+ //#endregion
159
+ export { CurrentTitleService, apply, formatTitle, frameMessages, inject, name, parseModelTitle, resolveTitleLocale, selectRecentMessages };
160
+ //# sourceMappingURL=index.d.ts.map