@j0hanz/cortex-mcp 1.2.0 → 1.3.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/README.md +2 -2
- package/dist/engine/config.d.ts +2 -1
- package/dist/engine/config.d.ts.map +1 -1
- package/dist/engine/config.js +7 -3
- package/dist/engine/config.js.map +1 -1
- package/dist/engine/context.d.ts +4 -4
- package/dist/engine/context.d.ts.map +1 -1
- package/dist/engine/context.js +3 -0
- package/dist/engine/context.js.map +1 -1
- package/dist/engine/events.d.ts +8 -9
- package/dist/engine/events.d.ts.map +1 -1
- package/dist/engine/events.js +6 -3
- package/dist/engine/events.js.map +1 -1
- package/dist/engine/reasoner.d.ts.map +1 -1
- package/dist/engine/reasoner.js +62 -33
- package/dist/engine/reasoner.js.map +1 -1
- package/dist/engine/session-store.d.ts +12 -1
- package/dist/engine/session-store.d.ts.map +1 -1
- package/dist/engine/session-store.js +109 -78
- package/dist/engine/session-store.js.map +1 -1
- package/dist/index.js +14 -7
- package/dist/index.js.map +1 -1
- package/dist/instructions.md +13 -13
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +16 -7
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/formatting.d.ts.map +1 -1
- package/dist/lib/formatting.js +32 -24
- package/dist/lib/formatting.js.map +1 -1
- package/dist/lib/instructions.d.ts.map +1 -1
- package/dist/lib/instructions.js +20 -4
- package/dist/lib/instructions.js.map +1 -1
- package/dist/lib/text.d.ts.map +1 -1
- package/dist/lib/text.js +23 -17
- package/dist/lib/text.js.map +1 -1
- package/dist/lib/tool-response.d.ts.map +1 -1
- package/dist/lib/tool-response.js +9 -6
- package/dist/lib/tool-response.js.map +1 -1
- package/dist/lib/types.d.ts +22 -12
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/validators.d.ts.map +1 -1
- package/dist/lib/validators.js +12 -10
- package/dist/lib/validators.js.map +1 -1
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +49 -75
- package/dist/prompts/index.js.map +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +66 -65
- package/dist/resources/index.js.map +1 -1
- package/dist/schemas/inputs.d.ts.map +1 -1
- package/dist/schemas/inputs.js +27 -48
- package/dist/schemas/inputs.js.map +1 -1
- package/dist/schemas/outputs.d.ts.map +1 -1
- package/dist/schemas/outputs.js +46 -24
- package/dist/schemas/outputs.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +69 -53
- package/dist/server.js.map +1 -1
- package/dist/tools/index.d.ts +0 -3
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/reasoning-think.d.ts.map +1 -1
- package/dist/tools/reasoning-think.js +105 -77
- package/dist/tools/reasoning-think.js.map +1 -1
- package/package.json +10 -7
package/dist/lib/formatting.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
const PIN_START = '<!-- pin:';
|
|
5
5
|
const PIN_END = '<!-- /pin -->';
|
|
6
|
+
const TRACE_SEPARATOR = '\n\n---\n\n';
|
|
7
|
+
const PINNED_SECTION_TITLE = '## 📌 Pinned';
|
|
6
8
|
/**
|
|
7
9
|
* Extract pinned sections from thought content.
|
|
8
10
|
*
|
|
@@ -18,28 +20,31 @@ const PIN_END = '<!-- /pin -->';
|
|
|
18
20
|
export function extractPinnedSections(thoughts) {
|
|
19
21
|
const byTitle = new Map();
|
|
20
22
|
for (const thought of thoughts) {
|
|
23
|
+
const { content } = thought;
|
|
21
24
|
let searchFrom = 0;
|
|
22
|
-
while (searchFrom <
|
|
23
|
-
const startIdx =
|
|
25
|
+
while (searchFrom < content.length) {
|
|
26
|
+
const startIdx = content.indexOf(PIN_START, searchFrom);
|
|
24
27
|
if (startIdx === -1) {
|
|
25
28
|
break;
|
|
26
29
|
}
|
|
27
|
-
const arrowIdx =
|
|
30
|
+
const arrowIdx = content.indexOf('-->', startIdx + PIN_START.length);
|
|
28
31
|
if (arrowIdx === -1) {
|
|
29
32
|
break;
|
|
30
33
|
}
|
|
31
|
-
const title =
|
|
32
|
-
.slice(startIdx + PIN_START.length, arrowIdx)
|
|
33
|
-
.trim();
|
|
34
|
+
const title = content.slice(startIdx + PIN_START.length, arrowIdx).trim();
|
|
34
35
|
const contentStart = arrowIdx + 3;
|
|
35
|
-
const endIdx =
|
|
36
|
+
const endIdx = content.indexOf(PIN_END, contentStart);
|
|
36
37
|
if (endIdx === -1) {
|
|
37
38
|
break;
|
|
38
39
|
}
|
|
39
|
-
const
|
|
40
|
+
const pinContent = content.slice(contentStart, endIdx).trim();
|
|
40
41
|
searchFrom = endIdx + PIN_END.length;
|
|
41
42
|
if (title.length > 0) {
|
|
42
|
-
byTitle.set(title, {
|
|
43
|
+
byTitle.set(title, {
|
|
44
|
+
title,
|
|
45
|
+
content: pinContent,
|
|
46
|
+
thoughtIndex: thought.index,
|
|
47
|
+
});
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
}
|
|
@@ -52,7 +57,7 @@ function renderPinnedSections(sections) {
|
|
|
52
57
|
if (sections.length === 0) {
|
|
53
58
|
return '';
|
|
54
59
|
}
|
|
55
|
-
const lines = [
|
|
60
|
+
const lines = [PINNED_SECTION_TITLE, ''];
|
|
56
61
|
for (const pin of sections) {
|
|
57
62
|
lines.push(`### ${pin.title} *(Thought ${String(pin.thoughtIndex + 1)})*`);
|
|
58
63
|
if (pin.content.length > 0) {
|
|
@@ -70,6 +75,17 @@ function formatThoughtHeading(thought) {
|
|
|
70
75
|
const suffix = thought.revision > 0 ? ' [Revised]' : '';
|
|
71
76
|
return `𖦹 Thought [${String(thoughtNumber)}]${suffix}`;
|
|
72
77
|
}
|
|
78
|
+
function renderThoughtSection(thought) {
|
|
79
|
+
return `${formatThoughtHeading(thought)}\n\n${thought.content}`;
|
|
80
|
+
}
|
|
81
|
+
function selectThoughts(allThoughts, range) {
|
|
82
|
+
if (!range) {
|
|
83
|
+
return allThoughts;
|
|
84
|
+
}
|
|
85
|
+
const startIndex = Math.max(0, range.start - 1);
|
|
86
|
+
const endIndex = Math.min(allThoughts.length, range.end);
|
|
87
|
+
return allThoughts.slice(startIndex, endIndex);
|
|
88
|
+
}
|
|
73
89
|
/**
|
|
74
90
|
* Format a session's thoughts as Markdown.
|
|
75
91
|
*
|
|
@@ -82,23 +98,16 @@ function formatThoughtHeading(thought) {
|
|
|
82
98
|
export function formatThoughtsToMarkdown(session, range) {
|
|
83
99
|
const { thoughts: allThoughts } = session;
|
|
84
100
|
const isFullTrace = range === undefined;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const startIndex = Math.max(0, range.start - 1);
|
|
88
|
-
const endIndex = Math.min(allThoughts.length, range.end);
|
|
89
|
-
thoughts = allThoughts.slice(startIndex, endIndex);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
thoughts = allThoughts;
|
|
93
|
-
}
|
|
101
|
+
const thoughts = selectThoughts(allThoughts, range);
|
|
102
|
+
const hasFullTraceThoughts = isFullTrace && thoughts.length > 0;
|
|
94
103
|
const sections = [];
|
|
95
104
|
// --- Header ---
|
|
96
|
-
if (
|
|
105
|
+
if (hasFullTraceThoughts) {
|
|
97
106
|
sections.push(`# Reasoning Trace — [${session.level}]\n` +
|
|
98
107
|
`> Session [${session.id}] · [${String(allThoughts.length)}] thoughts`);
|
|
99
108
|
}
|
|
100
109
|
// --- Pinned sections (full trace only) ---
|
|
101
|
-
if (
|
|
110
|
+
if (hasFullTraceThoughts) {
|
|
102
111
|
const pinned = extractPinnedSections(thoughts);
|
|
103
112
|
const pinnedMd = renderPinnedSections(pinned);
|
|
104
113
|
if (pinnedMd.length > 0) {
|
|
@@ -107,9 +116,8 @@ export function formatThoughtsToMarkdown(session, range) {
|
|
|
107
116
|
}
|
|
108
117
|
// --- Thought narrative ---
|
|
109
118
|
for (const thought of thoughts) {
|
|
110
|
-
|
|
111
|
-
sections.push(`${heading}\n\n${thought.content}`);
|
|
119
|
+
sections.push(renderThoughtSection(thought));
|
|
112
120
|
}
|
|
113
|
-
return sections.join(
|
|
121
|
+
return sections.join(TRACE_SEPARATOR);
|
|
114
122
|
}
|
|
115
123
|
//# sourceMappingURL=formatting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/lib/formatting.ts"],"names":[],"mappings":"AAYA,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,OAAO,GAAG,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/lib/formatting.ts"],"names":[],"mappings":"AAYA,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,OAAO,GAAG,eAAe,CAAC;AAChC,MAAM,eAAe,GAAG,aAAa,CAAC;AACtC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAA4B;IAE5B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEjD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC5B,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,OAAO,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YACxD,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;gBACpB,MAAM;YACR,CAAC;YAED,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAC,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,CACtC,OAA0B,EAC1B,KAAsC;IAEtC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC1C,MAAM,WAAW,GAAG,KAAK,KAAK,SAAS,CAAC;IACxC,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACpD,MAAM,oBAAoB,GAAG,WAAW,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAEhE,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,iBAAiB;IACjB,IAAI,oBAAoB,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CACX,wBAAwB,OAAO,CAAC,KAAK,KAAK;YACxC,cAAc,OAAO,CAAC,EAAE,QAAQ,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CACzE,CAAC;IACJ,CAAC;IAED,4CAA4C;IAC5C,IAAI,oBAAoB,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,4BAA4B;IAC5B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,SAAgC,GACvC,MAAM,CAiBR"}
|
package/dist/lib/instructions.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
+
const INSTRUCTIONS_URL = new URL('../instructions.md', import.meta.url);
|
|
3
|
+
const DEFAULT_INSTRUCTIONS_FALLBACK = '(Instructions not available)';
|
|
4
|
+
let cachedInstructionsText;
|
|
5
|
+
let instructionsLoadFailed = false;
|
|
6
|
+
function resolveInstructionsText(text, fallback) {
|
|
7
|
+
const trimmed = text.trim();
|
|
8
|
+
return trimmed.length > 0 ? trimmed : fallback;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* Loads the instructions from the instructions.md file. If the file cannot be read or is empty, returns a fallback message.
|
|
4
12
|
*/
|
|
5
|
-
export function loadInstructions(fallback =
|
|
13
|
+
export function loadInstructions(fallback = DEFAULT_INSTRUCTIONS_FALLBACK) {
|
|
14
|
+
if (cachedInstructionsText !== undefined) {
|
|
15
|
+
return resolveInstructionsText(cachedInstructionsText, fallback);
|
|
16
|
+
}
|
|
17
|
+
if (instructionsLoadFailed) {
|
|
18
|
+
return fallback;
|
|
19
|
+
}
|
|
6
20
|
try {
|
|
7
|
-
|
|
8
|
-
return text.length > 0 ? text : fallback;
|
|
21
|
+
cachedInstructionsText = readFileSync(INSTRUCTIONS_URL, 'utf8');
|
|
9
22
|
}
|
|
10
23
|
catch {
|
|
11
|
-
|
|
24
|
+
instructionsLoadFailed = true;
|
|
12
25
|
}
|
|
26
|
+
return cachedInstructionsText
|
|
27
|
+
? resolveInstructionsText(cachedInstructionsText, fallback)
|
|
28
|
+
: fallback;
|
|
13
29
|
}
|
|
14
30
|
//# sourceMappingURL=instructions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxE,MAAM,6BAA6B,GAAG,8BAA8B,CAAC;AACrE,IAAI,sBAA0C,CAAC;AAC/C,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC,SAAS,uBAAuB,CAAC,IAAY,EAAE,QAAgB;IAC7D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAQ,GAAG,6BAA6B;IAExC,IAAI,sBAAsB,KAAK,SAAS,EAAE,CAAC;QACzC,OAAO,uBAAuB,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,sBAAsB,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,IAAI,CAAC;QACH,sBAAsB,GAAG,YAAY,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB,GAAG,IAAI,CAAC;IAChC,CAAC;IAED,OAAO,sBAAsB;QAC3B,CAAC,CAAC,uBAAuB,CAAC,sBAAsB,EAAE,QAAQ,CAAC;QAC3D,CAAC,CAAC,QAAQ,CAAC;AACf,CAAC"}
|
package/dist/lib/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/lib/text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/lib/text.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,WAAW,EAAE,UAAU,GAAG,UAAU,GACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAS5B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,GACzB,MAAM,CAeR;AAyBD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY5E"}
|
package/dist/lib/text.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
+
const UTF8 = 'utf8';
|
|
4
|
+
const TRUNCATE_SUFFIX = '...';
|
|
5
|
+
const TRUNCATE_SUFFIX_BYTES = Buffer.byteLength(TRUNCATE_SUFFIX, UTF8);
|
|
6
|
+
function clampNonNegative(value) {
|
|
7
|
+
return Math.max(0, value);
|
|
8
|
+
}
|
|
9
|
+
function utf8ByteLength(value) {
|
|
10
|
+
return Buffer.byteLength(value, UTF8);
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* Creates an Intl.Segmenter instance if available in the environment.
|
|
5
14
|
* gracefully handles missing Intl support or specific locale issues.
|
|
@@ -19,51 +28,48 @@ export function createSegmenter(granularity) {
|
|
|
19
28
|
* Truncates a string to fit within a specified byte length, ensuring that it does not cut off in the middle of a grapheme cluster if possible.
|
|
20
29
|
*/
|
|
21
30
|
export function truncate(str, maxLength, segmenter) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const maxBytes = Math.max(0, maxLength);
|
|
25
|
-
const suffixBytes = Buffer.byteLength(suffix, 'utf8');
|
|
26
|
-
if (Buffer.byteLength(str, 'utf8') <= maxBytes) {
|
|
31
|
+
const maxBytes = clampNonNegative(maxLength);
|
|
32
|
+
if (utf8ByteLength(str) <= maxBytes) {
|
|
27
33
|
return str;
|
|
28
34
|
}
|
|
29
35
|
// If we can't even fit the suffix, just return the suffix truncated (e.g. "." or "..")
|
|
30
|
-
if (maxBytes <=
|
|
31
|
-
return
|
|
36
|
+
if (maxBytes <= TRUNCATE_SUFFIX_BYTES) {
|
|
37
|
+
return TRUNCATE_SUFFIX.slice(0, maxBytes);
|
|
32
38
|
}
|
|
33
|
-
const targetBytes = maxBytes -
|
|
39
|
+
const targetBytes = maxBytes - TRUNCATE_SUFFIX_BYTES;
|
|
34
40
|
const truncated = truncateByGrapheme(str, targetBytes, segmenter);
|
|
35
|
-
return truncated +
|
|
41
|
+
return truncated + TRUNCATE_SUFFIX;
|
|
36
42
|
}
|
|
37
43
|
function truncateByGrapheme(str, maxBytes, segmenter) {
|
|
38
44
|
if (!segmenter) {
|
|
39
45
|
return truncateByUtf8Boundary(str, maxBytes);
|
|
40
46
|
}
|
|
41
|
-
|
|
47
|
+
const segments = [];
|
|
42
48
|
let usedBytes = 0;
|
|
43
49
|
for (const part of segmenter.segment(str)) {
|
|
44
|
-
const segmentBytes =
|
|
50
|
+
const segmentBytes = utf8ByteLength(part.segment);
|
|
45
51
|
if (usedBytes + segmentBytes > maxBytes) {
|
|
46
52
|
break;
|
|
47
53
|
}
|
|
48
|
-
|
|
54
|
+
segments.push(part.segment);
|
|
49
55
|
usedBytes += segmentBytes;
|
|
50
56
|
}
|
|
51
|
-
return
|
|
57
|
+
return segments.join('');
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
54
60
|
* Truncates a string to fit within maxBytes, ensuring no partial UTF-8 characters are included.
|
|
55
61
|
* Drops incomplete characters at the end rather than using replacement characters.
|
|
56
62
|
*/
|
|
57
63
|
export function truncateByUtf8Boundary(str, maxBytes) {
|
|
58
|
-
const safeMaxBytes =
|
|
59
|
-
|
|
60
|
-
if (encoded.length <= safeMaxBytes) {
|
|
64
|
+
const safeMaxBytes = clampNonNegative(maxBytes);
|
|
65
|
+
if (utf8ByteLength(str) <= safeMaxBytes) {
|
|
61
66
|
return str;
|
|
62
67
|
}
|
|
63
68
|
if (safeMaxBytes === 0) {
|
|
64
69
|
return '';
|
|
65
70
|
}
|
|
66
|
-
const
|
|
71
|
+
const encoded = Buffer.from(str, UTF8);
|
|
72
|
+
const decoder = new StringDecoder(UTF8);
|
|
67
73
|
return decoder.write(encoded.subarray(0, safeMaxBytes));
|
|
68
74
|
}
|
|
69
75
|
//# sourceMappingURL=text.js.map
|
package/dist/lib/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/lib/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,WAAoC;IAEpC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;QACrE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CACtB,GAAW,EACX,SAAiB,EACjB,SAA0B;IAE1B,MAAM,
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/lib/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,C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
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-response.d.ts","sourceRoot":"","sources":["../../src/lib/tool-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACrB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-response.d.ts","sourceRoot":"","sources":["../../src/lib/tool-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACrB,MAAM,oCAAoC,CAAC;AAM5C,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EACjD,UAAU,EAAE,CAAC,EACb,gBAAgB,CAAC,EAAE,oBAAoB,GACtC;IACD,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,iBAAiB,EAAE,CAAC,CAAC;CACtB,CAaA"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
function createStructuredTextBlock(structured) {
|
|
2
|
+
return { type: 'text', text: JSON.stringify(structured) };
|
|
3
|
+
}
|
|
1
4
|
export function createToolResponse(structured, embeddedResource) {
|
|
2
|
-
const content =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const content = embeddedResource === undefined
|
|
6
|
+
? [createStructuredTextBlock(structured)]
|
|
7
|
+
: [
|
|
8
|
+
createStructuredTextBlock(structured),
|
|
9
|
+
{ type: 'resource', resource: embeddedResource },
|
|
10
|
+
];
|
|
8
11
|
return {
|
|
9
12
|
content,
|
|
10
13
|
structuredContent: structured,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-response.js","sourceRoot":"","sources":["../../src/lib/tool-response.ts"],"names":[],"mappings":"AAKA,
|
|
1
|
+
{"version":3,"file":"tool-response.js","sourceRoot":"","sources":["../../src/lib/tool-response.ts"],"names":[],"mappings":"AAKA,SAAS,yBAAyB,CAAC,UAAkB;IACnD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,UAAa,EACb,gBAAuC;IAKvC,MAAM,OAAO,GACX,gBAAgB,KAAK,SAAS;QAC5B,CAAC,CAAC,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC,CAAC;YACE,yBAAyB,CAAC,UAAU,CAAC;YACrC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE;SACjD,CAAC;IAER,OAAO;QACL,OAAO;QACP,iBAAiB,EAAE,UAAU;KAC9B,CAAC;AACJ,CAAC"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
1
|
export type ReasoningLevel = 'basic' | 'normal' | 'high';
|
|
2
2
|
export type ReasoningRunMode = 'step' | 'run_to_completion';
|
|
3
3
|
export type SessionStatus = 'active' | 'completed' | 'cancelled';
|
|
4
|
+
interface Timestamped {
|
|
5
|
+
readonly createdAt: number;
|
|
6
|
+
readonly updatedAt: number;
|
|
7
|
+
}
|
|
8
|
+
interface TokenTracked {
|
|
9
|
+
readonly tokenBudget: number;
|
|
10
|
+
readonly tokensUsed: number;
|
|
11
|
+
}
|
|
12
|
+
interface SessionBase extends Timestamped, TokenTracked {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly level: ReasoningLevel;
|
|
15
|
+
readonly status: SessionStatus;
|
|
16
|
+
readonly totalThoughts: number;
|
|
17
|
+
}
|
|
4
18
|
export interface Thought {
|
|
5
19
|
readonly index: number;
|
|
6
20
|
readonly content: string;
|
|
7
21
|
readonly revision: number;
|
|
8
22
|
}
|
|
9
|
-
export interface Session {
|
|
10
|
-
readonly id: string;
|
|
11
|
-
readonly level: ReasoningLevel;
|
|
12
|
-
readonly status: SessionStatus;
|
|
23
|
+
export interface Session extends SessionBase {
|
|
13
24
|
readonly thoughts: readonly Thought[];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
readonly
|
|
17
|
-
readonly createdAt: number;
|
|
18
|
-
readonly updatedAt: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SessionSummary extends SessionBase {
|
|
27
|
+
readonly generatedThoughts: number;
|
|
19
28
|
}
|
|
20
29
|
export interface LevelConfig {
|
|
21
|
-
minThoughts: number;
|
|
22
|
-
maxThoughts: number;
|
|
23
|
-
tokenBudget: number;
|
|
30
|
+
readonly minThoughts: number;
|
|
31
|
+
readonly maxThoughts: number;
|
|
32
|
+
readonly tokenBudget: number;
|
|
24
33
|
}
|
|
25
34
|
export interface IconMeta {
|
|
26
35
|
src: string;
|
|
27
36
|
mimeType: string;
|
|
28
37
|
sizes?: string[];
|
|
29
38
|
}
|
|
39
|
+
export {};
|
|
30
40
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AACzD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,mBAAmB,CAAC;AAE5D,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC;AAEjE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AACzD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,mBAAmB,CAAC;AAE5D,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC;AAEjE,UAAU,WAAW;IACnB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,UAAU,YAAY;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,WAAY,SAAQ,WAAW,EAAE,YAAY;IACrD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,OAAQ,SAAQ,WAAW;IAC1C,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;CACvC;AAED,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/lib/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/lib/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAsBjD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,GAAG;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,CAEA;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,cAAc,EACrB,cAAc,EAAE,MAAM,GACrB,MAAM,GAAG,SAAS,CAWpB"}
|
package/dist/lib/validators.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
/** Level-specific thought count boundaries for validation. */
|
|
2
|
-
const THOUGHT_BOUNDS = {
|
|
3
|
-
basic: {
|
|
4
|
-
normal: {
|
|
5
|
-
high: {
|
|
6
|
-
};
|
|
2
|
+
const THOUGHT_BOUNDS = Object.freeze({
|
|
3
|
+
basic: Object.freeze({ minThoughts: 3, maxThoughts: 5 }),
|
|
4
|
+
normal: Object.freeze({ minThoughts: 6, maxThoughts: 10 }),
|
|
5
|
+
high: Object.freeze({ minThoughts: 15, maxThoughts: 25 }),
|
|
6
|
+
});
|
|
7
|
+
function isOutOfBounds(value, bounds) {
|
|
8
|
+
return value < bounds.minThoughts || value > bounds.maxThoughts;
|
|
9
|
+
}
|
|
7
10
|
export function getThoughtBounds(level) {
|
|
8
|
-
|
|
9
|
-
return { minThoughts: min, maxThoughts: max };
|
|
11
|
+
return THOUGHT_BOUNDS[level];
|
|
10
12
|
}
|
|
11
13
|
export function getTargetThoughtsError(level, targetThoughts) {
|
|
12
14
|
if (!Number.isInteger(targetThoughts)) {
|
|
13
15
|
return 'targetThoughts must be an integer';
|
|
14
16
|
}
|
|
15
|
-
const
|
|
16
|
-
if (targetThoughts
|
|
17
|
-
return `targetThoughts must be between ${String(minThoughts)} and ${String(maxThoughts)} for level "${level}" (received ${String(targetThoughts)})`;
|
|
17
|
+
const levelBounds = getThoughtBounds(level);
|
|
18
|
+
if (isOutOfBounds(targetThoughts, levelBounds)) {
|
|
19
|
+
return `targetThoughts must be between ${String(levelBounds.minThoughts)} and ${String(levelBounds.maxThoughts)} for level "${level}" (received ${String(targetThoughts)})`;
|
|
18
20
|
}
|
|
19
21
|
return undefined;
|
|
20
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/lib/validators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/lib/validators.ts"],"names":[],"mappings":"AAOA,8DAA8D;AAC9D,MAAM,cAAc,GAClB,MAAM,CAAC,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;IACxD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IAC1D,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;CAC1D,CAAC,CAAC;AAEL,SAAS,aAAa,CACpB,KAAa,EACb,MAA+B;IAE/B,OAAO,KAAK,GAAG,MAAM,CAAC,WAAW,IAAI,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAqB;IAIpD,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAqB,EACrB,cAAsB;IAEtB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC;QACtC,OAAO,mCAAmC,CAAC;IAC7C,CAAC;IAED,MAAM,WAAW,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC5C,IAAI,aAAa,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE,CAAC;QAC/C,OAAO,kCAAkC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,eAAe,KAAK,eAAe,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC;IAC9K,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA4GhD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,EACjB,QAAQ,CAAC,EAAE,QAAQ,GAClB,IAAI,CA+FN"}
|
package/dist/prompts/index.js
CHANGED
|
@@ -4,8 +4,16 @@ import { sessionStore } from '../engine/reasoner.js';
|
|
|
4
4
|
import { loadInstructions } from '../lib/instructions.js';
|
|
5
5
|
const COMPLETION_LIMIT = 20;
|
|
6
6
|
const LEVEL_VALUES = ['basic', 'normal', 'high'];
|
|
7
|
+
const LEVEL_ENUM_SCHEMA = z.enum(LEVEL_VALUES);
|
|
8
|
+
const LEVEL_TITLES = {
|
|
9
|
+
basic: 'Basic',
|
|
10
|
+
normal: 'Normal',
|
|
11
|
+
high: 'High',
|
|
12
|
+
};
|
|
13
|
+
const REASONING_TOOL_NAME = 'reasoning_think';
|
|
14
|
+
const THOUGHT_PARAMETER_GUIDANCE = 'Provide your full reasoning in the "thought" parameter for each step.';
|
|
7
15
|
function levelTitle(level) {
|
|
8
|
-
return
|
|
16
|
+
return LEVEL_TITLES[level];
|
|
9
17
|
}
|
|
10
18
|
function formatTargetThoughts(targetThoughts) {
|
|
11
19
|
if (targetThoughts === undefined) {
|
|
@@ -15,11 +23,11 @@ function formatTargetThoughts(targetThoughts) {
|
|
|
15
23
|
}
|
|
16
24
|
function completeSessionId(value) {
|
|
17
25
|
const results = [];
|
|
18
|
-
for (const
|
|
19
|
-
if (!
|
|
26
|
+
for (const sessionId of sessionStore.listSessionIds()) {
|
|
27
|
+
if (!sessionId.startsWith(value)) {
|
|
20
28
|
continue;
|
|
21
29
|
}
|
|
22
|
-
results.push(
|
|
30
|
+
results.push(sessionId);
|
|
23
31
|
if (results.length >= COMPLETION_LIMIT) {
|
|
24
32
|
break;
|
|
25
33
|
}
|
|
@@ -28,17 +36,35 @@ function completeSessionId(value) {
|
|
|
28
36
|
}
|
|
29
37
|
function completeLevel(value) {
|
|
30
38
|
const normalized = value.toLowerCase();
|
|
31
|
-
|
|
39
|
+
const results = [];
|
|
40
|
+
for (const level of LEVEL_VALUES) {
|
|
41
|
+
if (level.startsWith(normalized)) {
|
|
42
|
+
results.push(level);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return results;
|
|
46
|
+
}
|
|
47
|
+
function withIconMeta(iconMeta) {
|
|
48
|
+
return iconMeta ? { icons: [iconMeta] } : undefined;
|
|
49
|
+
}
|
|
50
|
+
function createTextPrompt(text) {
|
|
51
|
+
return {
|
|
52
|
+
messages: [
|
|
53
|
+
{
|
|
54
|
+
role: 'user',
|
|
55
|
+
content: {
|
|
56
|
+
type: 'text',
|
|
57
|
+
text,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
};
|
|
32
62
|
}
|
|
33
63
|
function registerLevelPrompt(server, level, iconMeta) {
|
|
34
64
|
server.registerPrompt(`reasoning.${level}`, {
|
|
35
65
|
title: `Reasoning ${levelTitle(level)}`,
|
|
36
66
|
description: `Prepare a ${level}-depth reasoning request.`,
|
|
37
|
-
...(iconMeta
|
|
38
|
-
? {
|
|
39
|
-
icons: [iconMeta],
|
|
40
|
-
}
|
|
41
|
-
: {}),
|
|
67
|
+
...(withIconMeta(iconMeta) ?? {}),
|
|
42
68
|
argsSchema: {
|
|
43
69
|
query: z
|
|
44
70
|
.string()
|
|
@@ -55,18 +81,8 @@ function registerLevelPrompt(server, level, iconMeta) {
|
|
|
55
81
|
},
|
|
56
82
|
}, ({ query, targetThoughts }) => {
|
|
57
83
|
// Create user message
|
|
58
|
-
const text = `Initiate a ${level}-depth reasoning session for the query: ${JSON.stringify(query)}. Use the "
|
|
59
|
-
return
|
|
60
|
-
messages: [
|
|
61
|
-
{
|
|
62
|
-
role: 'user',
|
|
63
|
-
content: {
|
|
64
|
-
type: 'text',
|
|
65
|
-
text,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
84
|
+
const text = `Initiate a ${level}-depth reasoning session for the query: ${JSON.stringify(query)}. Use the "${REASONING_TOOL_NAME}" tool${formatTargetThoughts(targetThoughts)}. ${THOUGHT_PARAMETER_GUIDANCE} This is stored verbatim in the session trace. Repeat calls with the returned sessionId until totalThoughts is reached.`;
|
|
85
|
+
return createTextPrompt(text);
|
|
70
86
|
});
|
|
71
87
|
}
|
|
72
88
|
export function registerAllPrompts(server, iconMeta) {
|
|
@@ -76,20 +92,14 @@ export function registerAllPrompts(server, iconMeta) {
|
|
|
76
92
|
server.registerPrompt('reasoning.retry', {
|
|
77
93
|
title: 'Retry Reasoning',
|
|
78
94
|
description: 'Retry a failed reasoning task with modified parameters.',
|
|
79
|
-
...(iconMeta
|
|
80
|
-
? {
|
|
81
|
-
icons: [iconMeta],
|
|
82
|
-
}
|
|
83
|
-
: {}),
|
|
95
|
+
...(withIconMeta(iconMeta) ?? {}),
|
|
84
96
|
argsSchema: {
|
|
85
97
|
query: z
|
|
86
98
|
.string()
|
|
87
99
|
.min(1)
|
|
88
100
|
.max(10000)
|
|
89
101
|
.describe('The original or modified query'),
|
|
90
|
-
level: completable(
|
|
91
|
-
.enum(['basic', 'normal', 'high'])
|
|
92
|
-
.describe('The reasoning level to use'), (value) => completeLevel(value)),
|
|
102
|
+
level: completable(LEVEL_ENUM_SCHEMA.describe('The reasoning level to use'), (value) => completeLevel(value)),
|
|
93
103
|
targetThoughts: z
|
|
94
104
|
.number()
|
|
95
105
|
.int()
|
|
@@ -99,44 +109,19 @@ export function registerAllPrompts(server, iconMeta) {
|
|
|
99
109
|
.describe('Optional exact step count'),
|
|
100
110
|
},
|
|
101
111
|
}, ({ query, level, targetThoughts }) => {
|
|
102
|
-
const text = `Retry the reasoning session for query: ${JSON.stringify(query)}. Use the "
|
|
103
|
-
return
|
|
104
|
-
messages: [
|
|
105
|
-
{
|
|
106
|
-
role: 'user',
|
|
107
|
-
content: {
|
|
108
|
-
type: 'text',
|
|
109
|
-
text,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
};
|
|
112
|
+
const text = `Retry the reasoning session for query: ${JSON.stringify(query)}. Use the "${REASONING_TOOL_NAME}" tool with level="${level}"${formatTargetThoughts(targetThoughts)}. ${THOUGHT_PARAMETER_GUIDANCE}`;
|
|
113
|
+
return createTextPrompt(text);
|
|
114
114
|
});
|
|
115
115
|
const instructions = loadInstructions();
|
|
116
116
|
server.registerPrompt('get-help', {
|
|
117
117
|
title: 'Get Help',
|
|
118
118
|
description: 'Return the server usage instructions.',
|
|
119
|
-
...(iconMeta
|
|
120
|
-
|
|
121
|
-
icons: [iconMeta],
|
|
122
|
-
}
|
|
123
|
-
: {}),
|
|
124
|
-
}, () => ({
|
|
125
|
-
messages: [
|
|
126
|
-
{
|
|
127
|
-
role: 'user',
|
|
128
|
-
content: { type: 'text', text: instructions },
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
}));
|
|
119
|
+
...(withIconMeta(iconMeta) ?? {}),
|
|
120
|
+
}, () => createTextPrompt(instructions));
|
|
132
121
|
server.registerPrompt('reasoning.continue', {
|
|
133
122
|
title: 'Continue Reasoning',
|
|
134
123
|
description: 'Continue an existing reasoning session with a follow-up query.',
|
|
135
|
-
...(iconMeta
|
|
136
|
-
? {
|
|
137
|
-
icons: [iconMeta],
|
|
138
|
-
}
|
|
139
|
-
: {}),
|
|
124
|
+
...(withIconMeta(iconMeta) ?? {}),
|
|
140
125
|
argsSchema: {
|
|
141
126
|
sessionId: completable(z
|
|
142
127
|
.string()
|
|
@@ -149,9 +134,7 @@ export function registerAllPrompts(server, iconMeta) {
|
|
|
149
134
|
.max(10000)
|
|
150
135
|
.optional()
|
|
151
136
|
.describe('Follow-up query for the existing session'),
|
|
152
|
-
level: completable(
|
|
153
|
-
.enum(['basic', 'normal', 'high'])
|
|
154
|
-
.describe('Must match the session level'), (value) => completeLevel(value)),
|
|
137
|
+
level: completable(LEVEL_ENUM_SCHEMA.optional().describe('Optional in the tool; session level is used if provided'), (value) => completeLevel(value ?? '')),
|
|
155
138
|
targetThoughts: z
|
|
156
139
|
.number()
|
|
157
140
|
.int()
|
|
@@ -162,18 +145,9 @@ export function registerAllPrompts(server, iconMeta) {
|
|
|
162
145
|
},
|
|
163
146
|
}, ({ sessionId, query, level, targetThoughts }) => {
|
|
164
147
|
const followUpText = query === undefined ? '' : ` with follow-up: ${JSON.stringify(query)}`;
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
{
|
|
169
|
-
role: 'user',
|
|
170
|
-
content: {
|
|
171
|
-
type: 'text',
|
|
172
|
-
text,
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
};
|
|
148
|
+
const levelText = level === undefined ? '' : ` with level="${level}"`;
|
|
149
|
+
const text = `Continue reasoning session ${JSON.stringify(sessionId)}${followUpText}. Use "${REASONING_TOOL_NAME}"${levelText}${formatTargetThoughts(targetThoughts)}. ${THOUGHT_PARAMETER_GUIDANCE}`;
|
|
150
|
+
return createTextPrompt(text);
|
|
177
151
|
});
|
|
178
152
|
}
|
|
179
153
|
//# sourceMappingURL=index.js.map
|