@deepseek-ai/dsh-session-title-first-prompt-llm 0.2.2-rc.1 → 0.2.2-rc.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAGjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAQxC,OAAO,EAKL,KAAK,qBAAqB,EAE3B,MAAM,oCAAoC,CAAA;AAG3C,eAAO,MAAM,IAAI,mCAAmC,CAAA;AACpD,eAAO,MAAM,MAAM,UAAsC,CAAA;AAGzD,0FAA0F;AAC1F,MAAM,WAAW,MAAO,SAAQ,qBAAqB;IACnD,4CAA4C;IAC5C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,sEAAsE;IACtE,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAA;CACrC;AAED,8FAA8F;AAC9F,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAQ3B,CAAA;AAgGF;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAsBxD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAIjE,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,2BAA2B,GAI5B,MAAM,oCAAoC,CAAA;AAC3C,sBAAsB;AAEtB,MAAM,CAAC,MAAM,IAAI,GAAG,g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AAY,CAAC,QAAQ,CAAC;QACxB,EAAE,EAAE,aAAa;QACjB,SAAS,EAAE,cAAc;QACzB,KAAK,CAAC,QAAQ,CAAC,OAAO;YACpB,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;YACjC,IAAI,KAAK,KAAK,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;YAClG,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE;gBACnF,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC;gBAC9B,KAAK,EAAE,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC;gBAC7B,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;gBACxB,qBAAqB;aACtB,CAAC,CAAA;YACF,OAAO;gBACL,KAAK,EAAE,iBAAiB,CAAC,QAAQ,CAAC;gBAClC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC;gBACxB,KAAK,EAAE,QAAQ,CAAC,KAAK;aACtB,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-session-title-first-prompt-llm",
3
3
  "description": "First-message LLM provider plugin for DeepSeek Harness session titles",
4
- "version": "0.2.2-rc.1",
4
+ "version": "0.2.2-rc.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -24,32 +24,35 @@
24
24
  "files": [
25
25
  "locale/*.json",
26
26
  "lib/index.js",
27
- "lib/types/**/*.d.ts"
27
+ "lib/types/**/*.d.ts",
28
+ "lib/types/**/*.d.ts.map",
29
+ "lib/**/*.js.map",
30
+ "src"
28
31
  ],
29
32
  "license": "MIT",
30
33
  "peerDependencies": {
31
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
32
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
33
- "@deepseek-ai/dsh-session-title": "0.2.2-rc.1",
34
- "@deepseek-ai/dsh-session-title-llm": "0.2.2-rc.1",
34
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
35
+ "@deepseek-ai/dsh-session": "0.2.2-rc.2",
36
+ "@deepseek-ai/dsh-session-title": "0.2.2-rc.2",
37
+ "@deepseek-ai/dsh-session-title-llm": "0.2.2-rc.2",
35
38
  "@deepseek-ai/cordis": "~4.1.0"
36
39
  },
37
40
  "dependencies": {
38
- "@deepseek-ai/dsh-util-values": "0.2.2-rc.1",
41
+ "@deepseek-ai/dsh-util-values": "0.2.2-rc.2",
39
42
  "@deepseek-ai/schemastery": "~3.19.0"
40
43
  },
41
44
  "devDependencies": {
42
45
  "@deepseek-ai/cordis-plugin-include": "~1.1.0",
43
46
  "@deepseek-ai/cordis-plugin-loader": "~1.1.0",
44
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
45
- "@deepseek-ai/dsh-llm-deepseek": "0.2.2-rc.1",
46
- "@deepseek-ai/dsh-llm-deepseek-api-key": "0.2.2-rc.1",
47
- "@deepseek-ai/dsh-llm-pi-ai": "0.2.2-rc.1",
48
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
49
- "@deepseek-ai/dsh-session-title": "0.2.2-rc.1",
50
- "@deepseek-ai/dsh-session-title-llm": "0.2.2-rc.1",
47
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
48
+ "@deepseek-ai/dsh-llm-deepseek": "0.2.2-rc.2",
49
+ "@deepseek-ai/dsh-llm-deepseek-api-key": "0.2.2-rc.2",
50
+ "@deepseek-ai/dsh-llm-pi-ai": "0.2.2-rc.2",
51
+ "@deepseek-ai/dsh-session": "0.2.2-rc.2",
52
+ "@deepseek-ai/dsh-session-title": "0.2.2-rc.2",
53
+ "@deepseek-ai/dsh-session-title-llm": "0.2.2-rc.2",
51
54
  "@deepseek-ai/cordis": "~4.1.0",
52
- "@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
53
- "@deepseek-ai/dsh-agent-loop": "0.2.2-rc.1"
55
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.2",
56
+ "@deepseek-ai/dsh-agent-loop": "0.2.2-rc.2"
54
57
  }
55
58
  }
package/src/index.ts ADDED
@@ -0,0 +1,167 @@
1
+ /** First-human-message model provider for `ctx.sessionTitle`. */
2
+
3
+ /* jscpd:ignore-start -- both shipped providers import the same shared packages. */
4
+ import type { Context } from '@deepseek-ai/cordis'
5
+ import z from '@deepseek-ai/schemastery'
6
+ import type { LlmResolvedModelInfo, ReasoningEffortId } from '@deepseek-ai/dsh-llm'
7
+ import { assertNever } from '@deepseek-ai/dsh-util-values'
8
+ import {
9
+ normalizeSessionTitle,
10
+ SessionTitleProviderId,
11
+ type SessionTitleUserMessage,
12
+ } from '@deepseek-ai/dsh-session-title'
13
+ import {
14
+ executeSessionTitleLlm,
15
+ resolveSessionTitleLlmConfig,
16
+ SessionTitleLlmConfigFields,
17
+ type ResolvedSessionTitleLlmConfig,
18
+ type SessionTitleLlmConfig,
19
+ type SessionTitleLlmResponse,
20
+ } from '@deepseek-ai/dsh-session-title-llm'
21
+ /* jscpd:ignore-end */
22
+
23
+ export const name = 'session-title-first-prompt-llm'
24
+ export const inject = ['sessionTitle', 'llm', 'sessions']
25
+
26
+ /* jscpd:ignore-start -- each provider owns its title-length targets and reasoning control. */
27
+ /** Required execution controls plus this provider's title-length targets; no defaults. */
28
+ export interface Config extends SessionTitleLlmConfig {
29
+ /** Target word count for non-CJK titles. */
30
+ readonly targetWords: number
31
+ /** Target character count for Chinese, Japanese, or Korean titles. */
32
+ readonly targetCjkCharacters: number
33
+ }
34
+
35
+ /** Loader schema for this provider's required execution controls and title-length targets. */
36
+ export const Config: z<Config> = z.object({
37
+ targetWords: z.number().step(1).min(1).required(),
38
+ targetCjkCharacters: z.number().step(1).min(1).required(),
39
+ maxInputBytes: SessionTitleLlmConfigFields.maxInputBytes,
40
+ maxOutputTokens: SessionTitleLlmConfigFields.maxOutputTokens,
41
+ timeoutMs: SessionTitleLlmConfigFields.timeoutMs,
42
+ provider: SessionTitleLlmConfigFields.provider,
43
+ model: SessionTitleLlmConfigFields.model,
44
+ })
45
+
46
+ /** Validated immutable provider policy. */
47
+ interface ResolvedConfig extends ResolvedSessionTitleLlmConfig {
48
+ readonly targetWords: number
49
+ readonly targetCjkCharacters: number
50
+ }
51
+
52
+ /** Validate one positive title-length target. */
53
+ function assertTarget(name: 'targetWords' | 'targetCjkCharacters', value: number): number {
54
+ if (!Number.isInteger(value) || value <= 0) {
55
+ throw new Error(`session-title-first-prompt-llm: ${name} must be a positive integer`)
56
+ }
57
+ return value
58
+ }
59
+
60
+ /**
61
+ * Validate the shared execution controls and this provider's title-length targets.
62
+ * @param config - untrusted plugin configuration.
63
+ * @returns immutable provider policy.
64
+ */
65
+ function resolveConfig(config: Config): ResolvedConfig {
66
+ const { targetWords, targetCjkCharacters, ...execution } = config
67
+ return {
68
+ ...resolveSessionTitleLlmConfig(execution),
69
+ targetWords: assertTarget('targetWords', targetWords),
70
+ targetCjkCharacters: assertTarget('targetCjkCharacters', targetCjkCharacters),
71
+ }
72
+ }
73
+
74
+ /** Select the route's least supported reasoning effort for a title call. */
75
+ const selectReasoningEffort = (model: Readonly<LlmResolvedModelInfo>): ReasoningEffortId | undefined =>
76
+ model.reasoning?.efforts[0]?.id
77
+ /* jscpd:ignore-end */
78
+
79
+ /* jscpd:ignore-start -- independent provider strategies share only the execution module, not prompt or parsing policy. */
80
+ /** Language-aware system instruction for a title derived from one message. */
81
+ function systemPrompt(config: ResolvedConfig): string {
82
+ return [
83
+ 'Create a concise title for an AI coding-assistant session from the supplied human messages.',
84
+ 'Return only the title on one line, **in plain text of natural language**, with no quotes, prefix, explanation, Markdown, XML, or terminal control codes. No code is allowed.',
85
+ 'Use the language of the messages.',
86
+ `Aim for about ${config.targetWords} words in non-CJK languages or ${config.targetCjkCharacters} CJK characters.`,
87
+ 'If the messages give little to name, still return a short best-effort title, such as Greeting, instead of explaining.',
88
+ ].join('\n')
89
+ }
90
+
91
+ /** Frame the selected messages as JSON so user text cannot break structural delimiters. */
92
+ function frameMessages(messages: readonly SessionTitleUserMessage[]): string {
93
+ return `Generate the session title from this JSON array of human messages:\n${JSON.stringify(messages)}`
94
+ }
95
+
96
+ /** Asterisk emphasis wrapping a whole line, such as `**Title**`. */
97
+ const EMPHASIS_WRAPPER = /^(?<marker>\*{1,3})(?<inner>\S(?:.*\S)?)\k<marker>$/u
98
+
99
+ /**
100
+ * Take the title from model output: the first non-empty line, without
101
+ * asterisk emphasis that wraps that whole line. Models that disregard the
102
+ * one-line instruction put the title first and commentary after it. A line
103
+ * that is entirely `*` emphasis loses the marker pair even when the model
104
+ * meant it literally; the inner-marker check keeps emphasis inside a longer
105
+ * line, and the system instruction forbids Markdown.
106
+ */
107
+ function titleFromOutput(text: string): string {
108
+ const line = text.split(/\r?\n/u).map(item => item.trim()).find(item => item.length > 0) ?? ''
109
+ const groups = EMPHASIS_WRAPPER.exec(line)?.groups
110
+ const marker = groups?.['marker']
111
+ const inner = groups?.['inner']
112
+ return marker === undefined || inner === undefined || inner.includes(marker) ? line : inner
113
+ }
114
+
115
+ /** Reject terminal tool-call or max-token outcomes and derive one non-empty title from the text blocks. */
116
+ function titleFromResponse(response: SessionTitleLlmResponse): string {
117
+ switch (response.finish.kind) {
118
+ case 'stop':
119
+ break
120
+ case 'tool-calls':
121
+ throw new Error('session-title-llm: title output must contain text only')
122
+ case 'max-tokens':
123
+ throw new Error('session-title-llm: title output reached maxOutputTokens')
124
+ /* v8 ignore next -- closed SessionTitleLlmFinish union exhaustiveness guard */
125
+ default: return assertNever(response.finish, 'SessionTitleLlmFinish')
126
+ }
127
+ if (response.blocks.some(block => block.type === 'tool-call')) {
128
+ throw new Error('session-title-llm: title output must contain text only')
129
+ }
130
+ const text = response.blocks
131
+ .filter((block): block is Extract<(typeof response.blocks)[number], { type: 'text' }> => block.type === 'text')
132
+ .map(block => block.text)
133
+ .join(' ')
134
+ const title = normalizeSessionTitle(titleFromOutput(text), Number.MAX_SAFE_INTEGER)
135
+ if (title.length === 0) throw new Error('session-title-llm: title model produced no text')
136
+ return title
137
+ }
138
+ /* jscpd:ignore-end */
139
+
140
+ /**
141
+ * Register the first-prompt model provider.
142
+ * @param ctx - context exposing session-title, LLM, and session services.
143
+ * @param config - required route, target, byte, token, and timeout policy.
144
+ */
145
+ export function apply(ctx: Context, config: Config): void {
146
+ const resolved = resolveConfig(config)
147
+ const titleProvider = SessionTitleProviderId(name)
148
+ ctx.sessionTitle.register({
149
+ id: titleProvider,
150
+ automatic: 'first-prompt',
151
+ async generate(request) {
152
+ const first = request.messages[0]
153
+ if (first === undefined) throw new Error('first-prompt title provider requires one human message')
154
+ const response = await executeSessionTitleLlm(ctx, resolved, request, titleProvider, {
155
+ system: systemPrompt(resolved),
156
+ input: frameMessages([first]),
157
+ messageSeqs: [first.seq],
158
+ selectReasoningEffort,
159
+ })
160
+ return {
161
+ title: titleFromResponse(response),
162
+ messageSeqs: [first.seq],
163
+ model: response.model,
164
+ }
165
+ },
166
+ })
167
+ }