@dsh-plugin/dsh-dynamic-tools 0.0.1 → 0.1.0-dev.43450988228
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 +165 -165
- package/README.md +111 -111
- package/docs/DETAIL.md +1 -1
- package/docs/preview.svg +25 -25
- package/icon.svg +7 -7
- package/locale/en.json +7 -7
- package/locale/zh.json +7 -7
- package/package.json +75 -75
- package/src/catalog.ts +88 -88
- package/src/disclose.ts +151 -151
- package/src/disclosure.ts +147 -147
- package/src/executor.ts +145 -145
- package/src/fold.ts +104 -104
- package/src/index.ts +178 -178
- package/src/install.ts +91 -91
- package/src/render.ts +115 -115
- package/src/source.ts +20 -20
- package/src/tool-load.ts +105 -105
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "Dynamic tools",
|
|
4
|
-
"description": "Freezes the request tool list after a session's first step and delivers later tools as trailing context, so a mid-conversation tool change no longer rewrites the cached prompt prefix. Applies to the native tool executor; tools are classified by name, and a tool that the step does not admit fails with an actionable error instead of running.",
|
|
5
|
-
"detail": "docs/DETAIL.md"
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Dynamic tools",
|
|
4
|
+
"description": "Freezes the request tool list after a session's first step and delivers later tools as trailing context, so a mid-conversation tool change no longer rewrites the cached prompt prefix. Applies to the native tool executor; tools are classified by name, and a tool that the step does not admit fails with an actionable error instead of running.",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"title": "动态工具加载",
|
|
4
|
-
"description": "会话首步之后冻结请求中的工具列表,之后出现的工具以对话尾部消息下发,中途的工具变化不再重写已缓存的前缀。仅作用于原生工具执行器;按工具名分类,未在本步准入的工具会得到可执行的错误而不是被执行。",
|
|
5
|
-
"detail": "docs/DETAIL.md"
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "动态工具加载",
|
|
4
|
+
"description": "会话首步之后冻结请求中的工具列表,之后出现的工具以对话尾部消息下发,中途的工具变化不再重写已缓存的前缀。仅作用于原生工具执行器;按工具名分类,未在本步准入的工具会得到可执行的错误而不是被执行。",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dsh-plugin/dsh-dynamic-tools",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Keeps the tool declaration head of a request frozen and discloses tools registered later as trailing context, so mid-conversation tool changes stop invalidating the cached prompt prefix.",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"types": "./lib/index.d.ts",
|
|
9
|
-
"default": "./lib/index.js"
|
|
10
|
-
},
|
|
11
|
-
"./locale/*.json": "./locale/*.json",
|
|
12
|
-
"./icon": "./icon.svg"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"lib/**/*.js",
|
|
16
|
-
"lib/**/*.d.ts",
|
|
17
|
-
"src/**/*.ts",
|
|
18
|
-
"cordis.patch.yml",
|
|
19
|
-
"locale/*.json",
|
|
20
|
-
"docs",
|
|
21
|
-
"icon.svg",
|
|
22
|
-
"README.md",
|
|
23
|
-
"LICENSE"
|
|
24
|
-
],
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsc -p tsconfig.json",
|
|
27
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
|
-
"test": "node --test \"tests/*.test.ts\"",
|
|
29
|
-
"prepack": "npm run build"
|
|
30
|
-
},
|
|
31
|
-
"license": "LGPL-3.0-only",
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/dsh-plugins/dsh-dynamic-tools.git"
|
|
35
|
-
},
|
|
36
|
-
"publishConfig": {
|
|
37
|
-
"access": "public"
|
|
38
|
-
},
|
|
39
|
-
"keywords": [
|
|
40
|
-
"deepseek-harness",
|
|
41
|
-
"dsh",
|
|
42
|
-
"plugin",
|
|
43
|
-
"tools",
|
|
44
|
-
"prompt-cache"
|
|
45
|
-
],
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"@deepseek-ai/cordis": "~4.1.0",
|
|
48
|
-
"@deepseek-ai/dsh-agent": "^0.2.2-rc.2",
|
|
49
|
-
"@deepseek-ai/dsh-llm": "^0.2.2-rc.2",
|
|
50
|
-
"@deepseek-ai/dsh-scope": "^0.2.2-rc.2",
|
|
51
|
-
"@deepseek-ai/dsh-session": "^0.2.2-rc.2",
|
|
52
|
-
"@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.2",
|
|
53
|
-
"@deepseek-ai/dsh-tools": "^0.2.2-rc.2",
|
|
54
|
-
"@deepseek-ai/schemastery": "~3.19.0"
|
|
55
|
-
},
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"@deepseek-ai/cordis": "4.1.0",
|
|
58
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.2",
|
|
59
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.2",
|
|
60
|
-
"@deepseek-ai/dsh-scope": "0.2.2-rc.2",
|
|
61
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
62
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
|
|
63
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.2",
|
|
64
|
-
"@deepseek-ai/schemastery": "3.19.0",
|
|
65
|
-
"typescript": "5.9.3"
|
|
66
|
-
},
|
|
67
|
-
"engines": {
|
|
68
|
-
"dsh": ">=0.2.2-rc.2 <0.3.0"
|
|
69
|
-
},
|
|
70
|
-
"dsh": {
|
|
71
|
-
"bundle": {
|
|
72
|
-
"patch": "./cordis.patch.yml"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@dsh-plugin/dsh-dynamic-tools",
|
|
3
|
+
"version": "0.1.0-dev.43450988228",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Keeps the tool declaration head of a request frozen and discloses tools registered later as trailing context, so mid-conversation tool changes stop invalidating the cached prompt prefix.",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./locale/*.json": "./locale/*.json",
|
|
12
|
+
"./icon": "./icon.svg"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib/**/*.js",
|
|
16
|
+
"lib/**/*.d.ts",
|
|
17
|
+
"src/**/*.ts",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"locale/*.json",
|
|
20
|
+
"docs",
|
|
21
|
+
"icon.svg",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p tsconfig.json",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
|
+
"test": "node --test \"tests/*.test.ts\"",
|
|
29
|
+
"prepack": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"license": "LGPL-3.0-only",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/dsh-plugins/dsh-dynamic-tools.git"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"deepseek-harness",
|
|
41
|
+
"dsh",
|
|
42
|
+
"plugin",
|
|
43
|
+
"tools",
|
|
44
|
+
"prompt-cache"
|
|
45
|
+
],
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@deepseek-ai/cordis": "~4.1.0",
|
|
48
|
+
"@deepseek-ai/dsh-agent": "^0.2.2-rc.2",
|
|
49
|
+
"@deepseek-ai/dsh-llm": "^0.2.2-rc.2",
|
|
50
|
+
"@deepseek-ai/dsh-scope": "^0.2.2-rc.2",
|
|
51
|
+
"@deepseek-ai/dsh-session": "^0.2.2-rc.2",
|
|
52
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.2-rc.2",
|
|
53
|
+
"@deepseek-ai/dsh-tools": "^0.2.2-rc.2",
|
|
54
|
+
"@deepseek-ai/schemastery": "~3.19.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
58
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.2",
|
|
59
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.2",
|
|
60
|
+
"@deepseek-ai/dsh-scope": "0.2.2-rc.2",
|
|
61
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
62
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
|
|
63
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.2",
|
|
64
|
+
"@deepseek-ai/schemastery": "3.19.0",
|
|
65
|
+
"typescript": "5.9.3"
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"dsh": ">=0.2.2-rc.2 <0.3.0"
|
|
69
|
+
},
|
|
70
|
+
"dsh": {
|
|
71
|
+
"bundle": {
|
|
72
|
+
"patch": "./cordis.patch.yml"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/catalog.ts
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure classification and signature helpers for the frozen tool catalog.
|
|
3
|
-
* No Harness imports: these run under the Node type-stripping loader in tests.
|
|
4
|
-
*
|
|
5
|
-
* @module dsh-dynamic-tools/catalog
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/** Model-facing tool schema fields this plugin reads without Harness types. */
|
|
9
|
-
export interface ToolSchemaLike {
|
|
10
|
-
readonly name: string
|
|
11
|
-
readonly description: string
|
|
12
|
-
readonly parameters: Record<string, unknown>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** How one registered tool name is disclosed. */
|
|
16
|
-
export type ToolClass = 'inline' | 'dynamic'
|
|
17
|
-
|
|
18
|
-
/** Rules that decide which tools belong in the frozen declaration head. */
|
|
19
|
-
export interface ClassificationRules {
|
|
20
|
-
/** Exact names that never enter the frozen catalog. */
|
|
21
|
-
readonly dynamicNames: readonly string[]
|
|
22
|
-
/** Name prefixes that never enter the frozen catalog. */
|
|
23
|
-
readonly dynamicPrefixes: readonly string[]
|
|
24
|
-
/** Exact names forced into the catalog, overriding the rules above. */
|
|
25
|
-
readonly inlineNames: readonly string[]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Decide how one tool name is disclosed.
|
|
30
|
-
* @param name - registered tool name.
|
|
31
|
-
* @param rules - configured classification rules.
|
|
32
|
-
* @returns `inline` for the frozen catalog, `dynamic` for tail disclosure.
|
|
33
|
-
*/
|
|
34
|
-
export function classifyTool(name: string, rules: ClassificationRules): ToolClass {
|
|
35
|
-
if (rules.inlineNames.includes(name)) return 'inline'
|
|
36
|
-
if (rules.dynamicNames.includes(name)) return 'dynamic'
|
|
37
|
-
if (rules.dynamicPrefixes.some(prefix => name.startsWith(prefix))) return 'dynamic'
|
|
38
|
-
return 'inline'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Deterministic JSON text with object keys sorted, so equal schemas compare equal. */
|
|
42
|
-
function stableJson(value: unknown): string {
|
|
43
|
-
if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'null'
|
|
44
|
-
if (Array.isArray(value)) return `[${value.map(stableJson).join(',')}]`
|
|
45
|
-
const entries = Object.keys(value as Record<string, unknown>).sort()
|
|
46
|
-
.map(key => `${JSON.stringify(key)}:${stableJson((value as Record<string, unknown>)[key])}`)
|
|
47
|
-
return `{${entries.join(',')}}`
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Identity of one tool definition for change detection.
|
|
52
|
-
* Same-name registrations that differ only in key order share a signature.
|
|
53
|
-
* @param schema - model-facing schema of the definition.
|
|
54
|
-
* @returns a comparable signature string.
|
|
55
|
-
*/
|
|
56
|
-
export function toolSignature(schema: ToolSchemaLike): string {
|
|
57
|
-
return `${schema.name}\u0000${schema.description}\u0000${stableJson(schema.parameters)}`
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Split the registered definitions into the frozen catalog and tail disclosures.
|
|
62
|
-
* @param definitions - every definition visible to the agent at capture time.
|
|
63
|
-
* @param rules - configured classification rules.
|
|
64
|
-
* @returns inline schemas for the head and configured dynamic schemas.
|
|
65
|
-
*/
|
|
66
|
-
export function splitCatalog(
|
|
67
|
-
definitions: readonly ToolSchemaLike[],
|
|
68
|
-
rules: ClassificationRules,
|
|
69
|
-
): { inline: ToolSchemaLike[], dynamic: ToolSchemaLike[] } {
|
|
70
|
-
const inline: ToolSchemaLike[] = []
|
|
71
|
-
const dynamic: ToolSchemaLike[] = []
|
|
72
|
-
for (const definition of definitions) {
|
|
73
|
-
if (classifyTool(definition.name, rules) === 'inline') inline.push(definition)
|
|
74
|
-
else dynamic.push(definition)
|
|
75
|
-
}
|
|
76
|
-
return { inline, dynamic }
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const encoder = new TextEncoder()
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* JSON size of one definition as it would be disclosed.
|
|
83
|
-
* @param schema - model-facing schema of the definition.
|
|
84
|
-
* @returns UTF-8 byte length of its JSON encoding.
|
|
85
|
-
*/
|
|
86
|
-
export function schemaBytes(schema: ToolSchemaLike): number {
|
|
87
|
-
return encoder.encode(JSON.stringify(schema)).length
|
|
88
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Pure classification and signature helpers for the frozen tool catalog.
|
|
3
|
+
* No Harness imports: these run under the Node type-stripping loader in tests.
|
|
4
|
+
*
|
|
5
|
+
* @module dsh-dynamic-tools/catalog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Model-facing tool schema fields this plugin reads without Harness types. */
|
|
9
|
+
export interface ToolSchemaLike {
|
|
10
|
+
readonly name: string
|
|
11
|
+
readonly description: string
|
|
12
|
+
readonly parameters: Record<string, unknown>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** How one registered tool name is disclosed. */
|
|
16
|
+
export type ToolClass = 'inline' | 'dynamic'
|
|
17
|
+
|
|
18
|
+
/** Rules that decide which tools belong in the frozen declaration head. */
|
|
19
|
+
export interface ClassificationRules {
|
|
20
|
+
/** Exact names that never enter the frozen catalog. */
|
|
21
|
+
readonly dynamicNames: readonly string[]
|
|
22
|
+
/** Name prefixes that never enter the frozen catalog. */
|
|
23
|
+
readonly dynamicPrefixes: readonly string[]
|
|
24
|
+
/** Exact names forced into the catalog, overriding the rules above. */
|
|
25
|
+
readonly inlineNames: readonly string[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Decide how one tool name is disclosed.
|
|
30
|
+
* @param name - registered tool name.
|
|
31
|
+
* @param rules - configured classification rules.
|
|
32
|
+
* @returns `inline` for the frozen catalog, `dynamic` for tail disclosure.
|
|
33
|
+
*/
|
|
34
|
+
export function classifyTool(name: string, rules: ClassificationRules): ToolClass {
|
|
35
|
+
if (rules.inlineNames.includes(name)) return 'inline'
|
|
36
|
+
if (rules.dynamicNames.includes(name)) return 'dynamic'
|
|
37
|
+
if (rules.dynamicPrefixes.some(prefix => name.startsWith(prefix))) return 'dynamic'
|
|
38
|
+
return 'inline'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Deterministic JSON text with object keys sorted, so equal schemas compare equal. */
|
|
42
|
+
function stableJson(value: unknown): string {
|
|
43
|
+
if (value === null || typeof value !== 'object') return JSON.stringify(value) ?? 'null'
|
|
44
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(',')}]`
|
|
45
|
+
const entries = Object.keys(value as Record<string, unknown>).sort()
|
|
46
|
+
.map(key => `${JSON.stringify(key)}:${stableJson((value as Record<string, unknown>)[key])}`)
|
|
47
|
+
return `{${entries.join(',')}}`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Identity of one tool definition for change detection.
|
|
52
|
+
* Same-name registrations that differ only in key order share a signature.
|
|
53
|
+
* @param schema - model-facing schema of the definition.
|
|
54
|
+
* @returns a comparable signature string.
|
|
55
|
+
*/
|
|
56
|
+
export function toolSignature(schema: ToolSchemaLike): string {
|
|
57
|
+
return `${schema.name}\u0000${schema.description}\u0000${stableJson(schema.parameters)}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Split the registered definitions into the frozen catalog and tail disclosures.
|
|
62
|
+
* @param definitions - every definition visible to the agent at capture time.
|
|
63
|
+
* @param rules - configured classification rules.
|
|
64
|
+
* @returns inline schemas for the head and configured dynamic schemas.
|
|
65
|
+
*/
|
|
66
|
+
export function splitCatalog(
|
|
67
|
+
definitions: readonly ToolSchemaLike[],
|
|
68
|
+
rules: ClassificationRules,
|
|
69
|
+
): { inline: ToolSchemaLike[], dynamic: ToolSchemaLike[] } {
|
|
70
|
+
const inline: ToolSchemaLike[] = []
|
|
71
|
+
const dynamic: ToolSchemaLike[] = []
|
|
72
|
+
for (const definition of definitions) {
|
|
73
|
+
if (classifyTool(definition.name, rules) === 'inline') inline.push(definition)
|
|
74
|
+
else dynamic.push(definition)
|
|
75
|
+
}
|
|
76
|
+
return { inline, dynamic }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const encoder = new TextEncoder()
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* JSON size of one definition as it would be disclosed.
|
|
83
|
+
* @param schema - model-facing schema of the definition.
|
|
84
|
+
* @returns UTF-8 byte length of its JSON encoding.
|
|
85
|
+
*/
|
|
86
|
+
export function schemaBytes(schema: ToolSchemaLike): number {
|
|
87
|
+
return encoder.encode(JSON.stringify(schema)).length
|
|
88
|
+
}
|