@deepseek-ai/dsh-session-title 0.0.1-rc.1
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 +28 -0
- package/README.i18n.yaml +6 -0
- package/README.md +55 -0
- package/README.zh.md +55 -0
- package/lib/index.js +580 -0
- package/lib/invariant.js +38 -0
- package/lib/types/client.d.ts +10 -0
- package/lib/types/client.js +10 -0
- package/lib/types/index.d.ts +230 -0
- package/lib/types/index.js +601 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/invariant.js +41 -0
- package/lib/types/normalize.d.ts +24 -0
- package/lib/types/normalize.js +71 -0
- package/lib/types/types.d.ts +21 -0
- package/lib/types/types.js +11 -0
- package/package.json +65 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** Title text normalization and UTF-8-safe truncation. */
|
|
2
|
+
/** Operating-system-command escape sequences, including unterminated tails. */
|
|
3
|
+
const OSC_SEQUENCE = /(?:\u001B\]|\u009D)(?:(?!\u0007|\u001B\\)[\s\S])*(?:\u0007|\u001B\\|$)/gu;
|
|
4
|
+
/** Control-sequence-introducer escapes such as SGR color codes. */
|
|
5
|
+
const CSI_SEQUENCE = /(?:\u001B\[|\u009B)[0-?]*[ -/]*[@-~]/gu;
|
|
6
|
+
/** Remaining two-byte ESC control sequences. */
|
|
7
|
+
const ESC_SEQUENCE = /\u001B[@-_]/gu;
|
|
8
|
+
/** Non-whitespace C0/C1 control characters. */
|
|
9
|
+
const CONTROL_CHARACTER = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/gu;
|
|
10
|
+
/** Directional and invisible controls that can make a displayed title deceptive. */
|
|
11
|
+
const DIRECTIONAL_CONTROL = /[\u200B\u200E\u200F\u202A-\u202E\u2060-\u2064\u2066-\u206F\uFEFF]/gu;
|
|
12
|
+
/** Reject an invalid public text limit. */
|
|
13
|
+
function assertPositiveInteger(name, value) {
|
|
14
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
15
|
+
throw new Error(`${name} must be a positive integer`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Remove controls and produce one trimmed, whitespace-normalized line. */
|
|
19
|
+
function cleanTitleText(input) {
|
|
20
|
+
return input
|
|
21
|
+
.replace(OSC_SEQUENCE, '')
|
|
22
|
+
.replace(CSI_SEQUENCE, '')
|
|
23
|
+
.replace(ESC_SEQUENCE, '')
|
|
24
|
+
.replace(CONTROL_CHARACTER, '')
|
|
25
|
+
.replace(DIRECTIONAL_CONTROL, '')
|
|
26
|
+
.replace(/\s+/gu, ' ')
|
|
27
|
+
.trim();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Truncate a string to a UTF-8 byte budget without splitting a Unicode code point.
|
|
31
|
+
* @param input - normalized title text.
|
|
32
|
+
* @param maxBytes - positive UTF-8 byte budget.
|
|
33
|
+
* @returns the longest leading code-point prefix within the budget.
|
|
34
|
+
*/
|
|
35
|
+
export function truncateTitleUtf8(input, maxBytes) {
|
|
36
|
+
assertPositiveInteger('maxBytes', maxBytes);
|
|
37
|
+
if (Buffer.byteLength(input, 'utf8') <= maxBytes)
|
|
38
|
+
return input;
|
|
39
|
+
let used = 0;
|
|
40
|
+
let output = '';
|
|
41
|
+
for (const character of input) {
|
|
42
|
+
const bytes = Buffer.byteLength(character, 'utf8');
|
|
43
|
+
if (used + bytes > maxBytes)
|
|
44
|
+
break;
|
|
45
|
+
output += character;
|
|
46
|
+
used += bytes;
|
|
47
|
+
}
|
|
48
|
+
return output;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Normalize one accepted session title and enforce its UTF-8 byte budget.
|
|
52
|
+
* @param input - untrusted title text.
|
|
53
|
+
* @param maxBytes - positive maximum encoded size.
|
|
54
|
+
* @returns a terminal-safe one-line title, possibly empty after sanitization.
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeSessionTitle(input, maxBytes) {
|
|
57
|
+
return truncateTitleUtf8(cleanTitleText(input), maxBytes).trimEnd();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Derive the deterministic first-message fallback.
|
|
61
|
+
* @param input - text from the first eligible human message.
|
|
62
|
+
* @param maxWords - positive whitespace-delimited word cap.
|
|
63
|
+
* @param maxBytes - positive UTF-8 byte cap.
|
|
64
|
+
* @returns the normalized leading words within both limits.
|
|
65
|
+
*/
|
|
66
|
+
export function fallbackSessionTitle(input, maxWords, maxBytes) {
|
|
67
|
+
assertPositiveInteger('maxWords', maxWords);
|
|
68
|
+
const words = cleanTitleText(input).split(' ').filter(Boolean).slice(0, maxWords);
|
|
69
|
+
return truncateTitleUtf8(words.join(' '), maxBytes).trimEnd();
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure types of the title domain: the ONE home of the `title` projection-key
|
|
3
|
+
* declaration, free of this package's host-side value imports (cordis
|
|
4
|
+
* service, schemastery, the llm seam). Two namespace projections serve it —
|
|
5
|
+
* `./types` for host consumers, `./client/types` (the browser half-entry's
|
|
6
|
+
* re-export) for client aggregates — with zero content duplication.
|
|
7
|
+
*
|
|
8
|
+
* @module @deepseek-ai/dsh-session-title/types
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
declare module '@deepseek-ai/dsh-session-projection/types' {
|
|
12
|
+
interface SessionProjectionMap {
|
|
13
|
+
/**
|
|
14
|
+
* The session's current normalized title — the latest `session/title`
|
|
15
|
+
* event's text (last-wins), or `null` before the first title lands. A
|
|
16
|
+
* plain string: the shape the client list rows consume.
|
|
17
|
+
*/
|
|
18
|
+
title: string | null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure types of the title domain: the ONE home of the `title` projection-key
|
|
3
|
+
* declaration, free of this package's host-side value imports (cordis
|
|
4
|
+
* service, schemastery, the llm seam). Two namespace projections serve it —
|
|
5
|
+
* `./types` for host consumers, `./client/types` (the browser half-entry's
|
|
6
|
+
* re-export) for client aggregates — with zero content duplication.
|
|
7
|
+
*
|
|
8
|
+
* @module @deepseek-ai/dsh-session-title/types
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/dsh-session-title",
|
|
3
|
+
"description": "Log-backed session title service and provider registry for the DeepSeek Harness",
|
|
4
|
+
"version": "0.0.1-rc.1",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "restricted"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/session/session-title"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./invariant": {
|
|
22
|
+
"types": "./lib/types/invariant.d.ts",
|
|
23
|
+
"default": "./lib/invariant.js"
|
|
24
|
+
},
|
|
25
|
+
"./types": {
|
|
26
|
+
"types": "./lib/types/types.d.ts",
|
|
27
|
+
"default": "./lib/types/types.js"
|
|
28
|
+
},
|
|
29
|
+
"./client": {
|
|
30
|
+
"types": "./lib/types/client.d.ts",
|
|
31
|
+
"default": "./lib/types/client.js"
|
|
32
|
+
},
|
|
33
|
+
"./src/*": "./src/*",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"lib/index.js",
|
|
38
|
+
"lib/invariant.js",
|
|
39
|
+
"lib/types/**/*.js",
|
|
40
|
+
"lib/types/**/*.d.ts"
|
|
41
|
+
],
|
|
42
|
+
"license": "BSD-3-Clause",
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@deepseek-ai/dsh-brand": "^0.0.1-rc.1",
|
|
45
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1",
|
|
46
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.1",
|
|
47
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
48
|
+
"@deepseek-ai/dsh-session-projection": "^0.0.1-rc.1",
|
|
49
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"zod": "^4.4.3",
|
|
53
|
+
"@deepseek-ai/schemastery": "^3.18.1-rc.1"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@deepseek-ai/dsh-brand": "^0.0.1-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1",
|
|
58
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-session-persistence-jsonl": "^0.0.1-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-session-persistence-sqlite": "^0.0.1-rc.1",
|
|
62
|
+
"@deepseek-ai/dsh-session-projection": "^0.0.1-rc.1",
|
|
63
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1"
|
|
64
|
+
}
|
|
65
|
+
}
|