@dsh-plugin/dsh-dynamic-tools 0.0.1 → 0.1.0-dev.43582542989
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 +151 -111
- package/docs/DETAIL.md +1 -1
- package/docs/preview.svg +25 -25
- package/icon.svg +7 -7
- package/lib/catalog.d.ts +11 -0
- package/lib/catalog.js +21 -0
- package/lib/disclose.d.ts +9 -6
- package/lib/disclose.js +51 -16
- package/lib/disclosure.d.ts +34 -0
- package/lib/disclosure.js +50 -3
- package/lib/executor.d.ts +53 -3
- package/lib/executor.js +87 -13
- package/lib/fold.d.ts +2 -2
- package/lib/fold.js +32 -21
- package/lib/index.d.ts +6 -0
- package/lib/index.js +26 -2
- package/lib/install.js +1 -0
- package/lib/render.d.ts +10 -2
- package/lib/render.js +20 -7
- package/lib/strategy.d.ts +52 -0
- package/lib/strategy.js +63 -0
- package/lib/tool-load.d.ts +16 -5
- package/lib/tool-load.js +29 -14
- package/locale/en.json +7 -7
- package/locale/zh.json +7 -7
- package/package.json +75 -75
- package/src/catalog.ts +112 -88
- package/src/disclose.ts +199 -151
- package/src/disclosure.ts +212 -147
- package/src/executor.ts +234 -145
- package/src/fold.ts +114 -104
- package/src/index.ts +209 -178
- package/src/install.ts +92 -91
- package/src/render.ts +129 -115
- package/src/source.ts +20 -20
- package/src/strategy.ts +79 -0
- package/src/tool-load.ts +126 -105
package/LICENSE
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
-
Version 3, 29 June 2007
|
|
3
|
-
|
|
4
|
-
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
-
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
-
of this license document, but changing it is not allowed.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
This version of the GNU Lesser General Public License incorporates
|
|
10
|
-
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
-
License, supplemented by the additional permissions listed below.
|
|
12
|
-
|
|
13
|
-
0. Additional Definitions.
|
|
14
|
-
|
|
15
|
-
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
-
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
-
General Public License.
|
|
18
|
-
|
|
19
|
-
"The Library" refers to a covered work governed by this License,
|
|
20
|
-
other than an Application or a Combined Work as defined below.
|
|
21
|
-
|
|
22
|
-
An "Application" is any work that makes use of an interface provided
|
|
23
|
-
by the Library, but which is not otherwise based on the Library.
|
|
24
|
-
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
-
of using an interface provided by the Library.
|
|
26
|
-
|
|
27
|
-
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
-
Application with the Library. The particular version of the Library
|
|
29
|
-
with which the Combined Work was made is also called the "Linked
|
|
30
|
-
Version".
|
|
31
|
-
|
|
32
|
-
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
-
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
-
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
-
based on the Application, and not on the Linked Version.
|
|
36
|
-
|
|
37
|
-
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
-
object code and/or source code for the Application, including any data
|
|
39
|
-
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
-
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
-
|
|
42
|
-
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
-
|
|
44
|
-
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
-
without being bound by section 3 of the GNU GPL.
|
|
46
|
-
|
|
47
|
-
2. Conveying Modified Versions.
|
|
48
|
-
|
|
49
|
-
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
-
facility refers to a function or data to be supplied by an Application
|
|
51
|
-
that uses the facility (other than as an argument passed when the
|
|
52
|
-
facility is invoked), then you may convey a copy of the modified
|
|
53
|
-
version:
|
|
54
|
-
|
|
55
|
-
a) under this License, provided that you make a good faith effort to
|
|
56
|
-
ensure that, in the event an Application does not supply the
|
|
57
|
-
function or data, the facility still operates, and performs
|
|
58
|
-
whatever part of its purpose remains meaningful, or
|
|
59
|
-
|
|
60
|
-
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
-
this License applicable to that copy.
|
|
62
|
-
|
|
63
|
-
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
-
|
|
65
|
-
The object code form of an Application may incorporate material from
|
|
66
|
-
a header file that is part of the Library. You may convey such object
|
|
67
|
-
code under terms of your choice, provided that, if the incorporated
|
|
68
|
-
material is not limited to numerical parameters, data structure
|
|
69
|
-
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
-
(ten or fewer lines in length), you do both of the following:
|
|
71
|
-
|
|
72
|
-
a) Give prominent notice with each copy of the object code that the
|
|
73
|
-
Library is used in it and that the Library and its use are
|
|
74
|
-
covered by this License.
|
|
75
|
-
|
|
76
|
-
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
-
document.
|
|
78
|
-
|
|
79
|
-
4. Combined Works.
|
|
80
|
-
|
|
81
|
-
You may convey a Combined Work under terms of your choice that,
|
|
82
|
-
taken together, effectively do not restrict modification of the
|
|
83
|
-
portions of the Library contained in the Combined Work and reverse
|
|
84
|
-
engineering for debugging such modifications, if you also do each of
|
|
85
|
-
the following:
|
|
86
|
-
|
|
87
|
-
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
-
the Library is used in it and that the Library and its use are
|
|
89
|
-
covered by this License.
|
|
90
|
-
|
|
91
|
-
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
-
document.
|
|
93
|
-
|
|
94
|
-
c) For a Combined Work that displays copyright notices during
|
|
95
|
-
execution, include the copyright notice for the Library among
|
|
96
|
-
these notices, as well as a reference directing the user to the
|
|
97
|
-
copies of the GNU GPL and this license document.
|
|
98
|
-
|
|
99
|
-
d) Do one of the following:
|
|
100
|
-
|
|
101
|
-
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
-
License, and the Corresponding Application Code in a form
|
|
103
|
-
suitable for, and under terms that permit, the user to
|
|
104
|
-
recombine or relink the Application with a modified version of
|
|
105
|
-
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
-
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
-
Corresponding Source.
|
|
108
|
-
|
|
109
|
-
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
-
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
-
a copy of the Library already present on the user's computer
|
|
112
|
-
system, and (b) will operate properly with a modified version
|
|
113
|
-
of the Library that is interface-compatible with the Linked
|
|
114
|
-
Version.
|
|
115
|
-
|
|
116
|
-
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
-
be required to provide such information under section 6 of the
|
|
118
|
-
GNU GPL, and only to the extent that such information is
|
|
119
|
-
necessary to install and execute a modified version of the
|
|
120
|
-
Combined Work produced by recombining or relinking the
|
|
121
|
-
Application with a modified version of the Linked Version. (If
|
|
122
|
-
you use option 4d0, the Installation Information must accompany
|
|
123
|
-
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
-
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
-
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
-
for conveying Corresponding Source.)
|
|
127
|
-
|
|
128
|
-
5. Combined Libraries.
|
|
129
|
-
|
|
130
|
-
You may place library facilities that are a work based on the
|
|
131
|
-
Library side by side in a single library together with other library
|
|
132
|
-
facilities that are not Applications and are not covered by this
|
|
133
|
-
License, and convey such a combined library under terms of your
|
|
134
|
-
choice, if you do both of the following:
|
|
135
|
-
|
|
136
|
-
a) Accompany the combined library with a copy of the same work based
|
|
137
|
-
on the Library, uncombined with any other library facilities,
|
|
138
|
-
conveyed under the terms of this License.
|
|
139
|
-
|
|
140
|
-
b) Give prominent notice with the combined library that part of it
|
|
141
|
-
is a work based on the Library, and explaining where to find the
|
|
142
|
-
accompanying uncombined form of the same work.
|
|
143
|
-
|
|
144
|
-
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
-
|
|
146
|
-
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
-
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
-
versions will be similar in spirit to the present version, but may
|
|
149
|
-
differ in detail to address new problems or concerns.
|
|
150
|
-
|
|
151
|
-
Each version is given a distinguishing version number. If the
|
|
152
|
-
Library as you received it specifies that a certain numbered version
|
|
153
|
-
of the GNU Lesser General Public License "or any later version"
|
|
154
|
-
applies to it, you have the option of following the terms and
|
|
155
|
-
conditions either of that published version or of any later version
|
|
156
|
-
published by the Free Software Foundation. If the Library as you
|
|
157
|
-
received it does not specify a version number of the GNU Lesser
|
|
158
|
-
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
-
General Public License ever published by the Free Software Foundation.
|
|
160
|
-
|
|
161
|
-
If the Library as you received it specifies that a proxy can decide
|
|
162
|
-
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
-
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
-
permanent authorization for you to choose that version for the
|
|
165
|
-
Library.
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
CHANGED
|
@@ -1,111 +1,151 @@
|
|
|
1
|
-
# Dynamic tools
|
|
2
|
-
|
|
3
|
-
冻结会话首步的工具声明头部,把之后才出现的工具以对话尾部消息下发。这样中途的工具变化不再改写请求前缀,模型提供方的缓存可以继续复用。
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
</
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
##
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1
|
+
# Dynamic tools
|
|
2
|
+
|
|
3
|
+
冻结会话首步的工具声明头部,把之后才出现的工具以对话尾部消息下发。这样中途的工具变化不再改写请求前缀,模型提供方的缓存可以继续复用。
|
|
4
|
+
|
|
5
|
+
对只调用 `tools` 数组内函数的模型(GPT 系列走 OpenAI Responses 协议),尾部文本读得到却调不了,因此另有一条「按需声明」通道:调用 `tool_load` 后再把该工具补进声明。见[GPT 系列路由](#gpt-系列路由按需声明)。
|
|
6
|
+
|
|
7
|
+
## 解决什么问题
|
|
8
|
+
|
|
9
|
+
DSH 的 `agent-loop` 在工具集发生变化、且当前路由没有声明 `toolUpdate` 能力时,会开启新的请求序列并重发完整系统提示词与工具声明。`openai-responses` 系列路由的 `supportsAdditionalTools` 在 `dsh-llm-pi-ai` 中被固定为 `withhold`,无法在 profile 里打开,所以在这类路由上:
|
|
10
|
+
|
|
11
|
+
- 进入计划模式时原生 `exit_plan_mode` 被准入 → 工具表变化 → 整个前缀失效;
|
|
12
|
+
- MCP 服务器晚连接、插件热插拔、条件工具转为可用,都会造成同样的失效。
|
|
13
|
+
|
|
14
|
+
本插件把声明头部固定下来:首步的声明集合被冻结,之后出现或被准入的工具通过尾部消息交给模型,模型仍可直接按名调用。只认声明列表的路由则走「按需声明」,多一次 `tool_load` 换取原生可调用。
|
|
15
|
+
|
|
16
|
+
## 机制
|
|
17
|
+
|
|
18
|
+
1. **冻结头部**:每个 Agent 在首步组装时捕获其准入定义,剔除配置为动态的名字,深冻结后每一步原样返回。头部之后不再变化。
|
|
19
|
+
2. **尾部披露**:`agent/pre-step` 在其它监听器之后运行,把"本步已准入但不在头部"的工具以一条用户消息披露;消息里既有名字清单,也有完整定义(`disclosure.mode: schema`),并带上"可直接按名调用"的说明。定义变化按签名检测后重披露,工具失去准入时追加 `<tools_removed>`。只注册、`when` 判为不可用的工具不会被公告——否则模型会去调用一个注定被拒的工具。
|
|
20
|
+
3. **声明≠准入**:头部里的工具若本步未被准入(`when` 判定为假),调用会在策略与审批之前返回一条可执行错误,绝不执行。工具被撤下时 `UNKNOWN_TOOL`。
|
|
21
|
+
4. **可见即记录**:披露消息带 `source.kind = dynamic-tools`,resume、fork、compaction 后由历史折叠重建;被压缩遮蔽的内容会在下一次开始时重发。
|
|
22
|
+
5. **按需加载**:`disclosure.mode: names` 时只报名字,模型调用 `tool_load` 取完整定义;`disclosure.requireLoad` 可要求动态工具必须先加载才能执行。
|
|
23
|
+
6. **按需声明**:命中 [`declareOnLoad`](#gpt-系列路由按需声明) 的路由把"已加载"的定义补进头部,让只认声明列表的模型也能调用动态工具。
|
|
24
|
+
|
|
25
|
+
披露消息形状:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
<system-reminder>
|
|
29
|
+
<tools_added>
|
|
30
|
+
- exit_plan_mode: Use only in plan mode. …
|
|
31
|
+
</tools_added>
|
|
32
|
+
|
|
33
|
+
<tool_definition name="exit_plan_mode">
|
|
34
|
+
{"name":"exit_plan_mode","description":"…","parameters":{…}}
|
|
35
|
+
</tool_definition>
|
|
36
|
+
|
|
37
|
+
These tools are callable directly by name even though they are not in your tool list; match the definitions above.
|
|
38
|
+
</system-reminder>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## GPT 系列路由:按需声明
|
|
42
|
+
|
|
43
|
+
OpenAI Responses 系路由只调用请求 `tools` 数组里声明过的函数。把定义写进对话文本时,这类模型只把它当作对话内容:没有声明就没有可调用的名字,它也不会为了看不见的定义去 `tool_load`。本插件在这类路由上切到 `declare`:
|
|
44
|
+
|
|
45
|
+
1. 动态工具被准入时只公告名字(`<tools_added>` 与 `<tools_load_required>`),不带完整定义。
|
|
46
|
+
2. 模型调用 `tool_load`(在头部,必定可调用)拿到定义。
|
|
47
|
+
3. 该工具从下一步起进入请求的 `tools` 声明,模型直接按名调用;参数校验用的正是它读到的定义。
|
|
48
|
+
|
|
49
|
+
`tool_load` 只服务本会话公告过的名字:已注册但从未公告的工具(例如 `when` 判为不可用)返回 `Unavailable`,否则猜中的名字也会被永久塞进头部。`alreadyAvailable` 只表示"已在工具列表里",不再重复下发。
|
|
50
|
+
|
|
51
|
+
这与 codex 的 `tool_search` → `tool_search_output` → 调用是同一形态。区别只在 codex 用 BM25 检索候选,本插件的公告已经给出确切名字,因此少一次检索回合,也不需要索引。
|
|
52
|
+
|
|
53
|
+
声明是单调的:已加载的工具此后一直留在头部,即使它失去准入或被注销。失去准入时调用返回 `unavailableReasons` 里的可执行拒绝,注销时得到 `UNKNOWN_TOOL`;头部不回撤,一次 `when` 抖动不会再把前缀打散。
|
|
54
|
+
|
|
55
|
+
代价是「每个加载过的工具一次前缀变化」:首个动态工具加载后请求头发生变化(`request/header` 的 `reason` 为 `change`),前缀从该点重建,此后只要不再加载新工具就保持稳定。动态工具用得越多,这笔一次性的账越接近默认策略的收益。
|
|
56
|
+
|
|
57
|
+
为什么不走原生 `tool_search`:`dsh-llm-pi-ai` 只在模型 compat 打开 `supportsToolSearch` 或 `supportsAdditionalTools` 时才把工具变化写成 `tool-addition`,而它对 `openai-responses`、`azure-openai-responses`、`openai-codex-responses` 三个协议把这两项固定标为 `withhold`,profile 打不开。所以这里由插件自己补一次声明。
|
|
58
|
+
|
|
59
|
+
## 安装
|
|
60
|
+
|
|
61
|
+
```powershell
|
|
62
|
+
npm install --ignore-scripts --legacy-peer-deps
|
|
63
|
+
npm run typecheck
|
|
64
|
+
npm run build
|
|
65
|
+
npm test
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
源码在 `src/`,运行时加载提交在仓库里的 `lib/`。所有 `@deepseek-ai/*` 都是 `peerDependencies`:以目录链接方式安装时,Harness 只把祖先 `package.json` 中声明为 peer 的名字解析到安装副本;`devDependencies` 只供 `tsc` 使用。`npm test` 用 Node 24+ 的原生类型剥离直接运行 `tests/*.test.ts`,只需在源码改动后重新构建。
|
|
69
|
+
|
|
70
|
+
通过 `plugin_manager` 的 `install_bundle` 安装本目录;`cordis.patch.yml` 插入一行 Host 入口:
|
|
71
|
+
|
|
72
|
+
```yaml
|
|
73
|
+
- insert:
|
|
74
|
+
- id: dynamic-tools
|
|
75
|
+
name: '@dsh-plugin/dsh-dynamic-tools'
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
以目录链接方式安装后,重新执行 `npm run build` **不会**让正在运行的实例换用新产物:模块 URL 不变,Node 的 ESM 缓存不会重新读盘,热重载也不重新导入它。改完源码并构建后需重启 dsh 实例,新会话才会加载新的 `lib/`。
|
|
79
|
+
|
|
80
|
+
## 配置
|
|
81
|
+
|
|
82
|
+
```yaml
|
|
83
|
+
- id: dynamic-tools
|
|
84
|
+
name: '@dsh-plugin/dsh-dynamic-tools'
|
|
85
|
+
config:
|
|
86
|
+
dynamic:
|
|
87
|
+
names: ['exit_plan_mode']
|
|
88
|
+
prefixes: ['mcp__']
|
|
89
|
+
disclosure:
|
|
90
|
+
mode: schema
|
|
91
|
+
declareOnLoad:
|
|
92
|
+
models: ['gpt*', 'o1*', 'o3*', 'o4*', 'chatgpt*', 'codex*']
|
|
93
|
+
providers: []
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| 字段 | 默认 | 说明 |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| `installExistingAgents` | `true` | 加载时对已存在的 Agent 补装 |
|
|
99
|
+
| `skipPresets` | `['ptc']` | 这些预设自带执行器,本插件不接管(PTC 只能看到 `run_code`) |
|
|
100
|
+
| `dynamic.names` | `['exit_plan_mode']` | 永不进入头部的精确工具名 |
|
|
101
|
+
| `dynamic.prefixes` | `[]` | 同上,按前缀匹配(如 `mcp__`) |
|
|
102
|
+
| `dynamic.inlineNames` | `[]` | 强制进入头部,覆盖上面两条;`tool_load` 恒在其中 |
|
|
103
|
+
| `disclosure.mode` | `schema` | `schema` 附完整定义;`names` 只报名字,需用 `tool_load` |
|
|
104
|
+
| `disclosure.requireLoad` | `false` | 动态工具必须先 `tool_load` 才能执行 |
|
|
105
|
+
| `disclosure.maxToolsPerMessage` | `8` | 单条披露消息的工具数 |
|
|
106
|
+
| `disclosure.maxSchemaBytes` | `6000` | 单个定义上限,超出转为名字公告 |
|
|
107
|
+
| `disclosure.maxMessageBytes` | `20000` | 单条消息上限,超出拆条 |
|
|
108
|
+
| `disclosure.announceRemovals` | `true` | 工具失去准入时追加 `<tools_removed>` |
|
|
109
|
+
| `declareOnLoad.models` | `['gpt*', 'o1*', 'o3*', 'o4*', 'chatgpt*', 'codex*']` | 命中这些模型名的路由改用按需声明 |
|
|
110
|
+
| `declareOnLoad.providers` | `[]` | 同上,按路由名限制;空表示不限路由 |
|
|
111
|
+
| `unavailableReasons` | `{ exit_plan_mode: … }` | 头部工具未准入时的模型可见原因 |
|
|
112
|
+
| `maxParallelCalls` | `10` | 循环未给出并发上限时使用 |
|
|
113
|
+
|
|
114
|
+
分类只看名字,因为注册时的 `when` 条件对插件不可见;未列入 `dynamic` 的工具默认进入头部。工具一旦进入头部就保持声明,即使当前不可调用——这正是缓存稳定的代价与保证。
|
|
115
|
+
|
|
116
|
+
`declareOnLoad` 的两个列表都支持 `*` 通配、大小写不敏感、整串匹配(`gpt*` 不匹配 `x-gpt-6`,`gpt-6.1*` 里的 `.` 是字面点)。两个列表为空表示强制所有路由走按需声明;策略按每一步的模型选择重算,中途切模型会随之切换。
|
|
117
|
+
|
|
118
|
+
## 模型体验
|
|
119
|
+
|
|
120
|
+
### 模型看到什么
|
|
121
|
+
|
|
122
|
+
`tail` 路由:头部声明保持不变。动态工具在本步首次被准入时以一条 `<system-reminder>` 出现:名字 + 描述 + 完整 JSON 定义 + "可直接按名调用"的说明;移除时出现 `<tools_removed>`。`names` 模式下模型需先调 `tool_load`,定义在其结果之后作为用户消息到达。
|
|
123
|
+
|
|
124
|
+
`declare` 路由:公告只给名字,说明改为"调用 `tool_load` 把名字加进工具列表,之后直接调用";`tool_load` 的结果除了定义还会说明"从下一步起已声明"。
|
|
125
|
+
|
|
126
|
+
### Token 影响
|
|
127
|
+
|
|
128
|
+
头部每步大小固定;披露只在工具真正增减时追加一次。相比每步重发全部声明,动态工具越多、会话越长,节省越明显。定义上限保护单条消息不被超大 schema 撑大。
|
|
129
|
+
|
|
130
|
+
`declare` 路由上,每个被加载的工具会长期占据头部一份定义;只有确定要用的工具才值得加载一次。
|
|
131
|
+
|
|
132
|
+
### KV Cache 影响
|
|
133
|
+
|
|
134
|
+
`tail` 路由:前缀在会话内保持字节稳定,工具声明、系统提示词都不再随工具状态变化。这是本插件的全部目的——实测进入计划模式后,切换点的缓存命中读数保持在同一量级而不是归零。
|
|
135
|
+
|
|
136
|
+
`declare` 路由:稳定区间是「两次加载之间」。每次 `tool_load` 生效后的下一步会重发一次声明与系统提示词(`request/header` 的 `reason` 为 `change`),此后不再变化。代价是模型必须先加载再调用,且披露本身会新增若干 token。
|
|
137
|
+
|
|
138
|
+
## 已知限制
|
|
139
|
+
|
|
140
|
+
- **首次捕获时机**:头部在 Agent 首步组装时捕获。若插件在会话中途安装,或 resume 后注册集合与历史头部不同,会出现一次头部变化,此后稳定。
|
|
141
|
+
- **PTC 预设不接管**:PTC 只能用 `run_code`,其 SDK 文本随工具集变化;冻结 `tools:sdk` 不在本版范围。命中 `skipPresets` 时插件对该 Agent 完全让位并记录一次 info 日志。
|
|
142
|
+
- **分类靠配置**:`when` 条件不可见,无法自动识别"条件工具";动态名单需要按名称或前缀配置。
|
|
143
|
+
- **路由匹配靠配置**:`declareOnLoad` 只认模型名与路由名;换供应商、改模型别名后需要同步,否则会退回 `tail` 策略而不是猜。
|
|
144
|
+
- **会话中切模型会有一次头部变化**:从 `tail` 切到 `declare` 时,此前的披露已经算作"已加载",这些工具会直接进入头部;反向切换则退回初始的冻结集合。两端都是一次性变化,之后各自稳定。
|
|
145
|
+
- **声明单调**:`declare` 路由上加载过的工具不再回撤。工具注销后仍留在头部,调用得到 `UNKNOWN_TOOL`;这换来的是 `when` 抖动不打断缓存。
|
|
146
|
+
- **`declare` 下强制名字公告**:该策略要把"已加载"当作声明依据,附完整定义会被记成已加载,因此 `disclosure.mode` 在该路由上不生效,首次切换时记录一条 info 日志。
|
|
147
|
+
- **定义漂移**:已加载且仍准入的工具,声明用注册表里的实时定义(保证参数校验与执行一致),可能与模型当初读到的版本不同。
|
|
148
|
+
- **超大定义**:超过 `maxSchemaBytes` 的工具在 `tail` 路由仍按名字公告(模型可直呼其名),在 `declare` 路由则完全不公告——那里只能靠加载,公告一个注定加载失败的名字只会浪费回合;两种情况都会记录一次 warn。
|
|
149
|
+
- **重放外观**:披露消息在 Chat 里显示为普通用户上下文;重放时工具卡片使用通用样式。
|
|
150
|
+
- **拒绝文案**:默认只预置 `exit_plan_mode` 的原因,其它头部工具的拒绝信息是通用文案,可通过 `unavailableReasons` 覆盖。
|
|
151
|
+
- **无 UI 控制**:没有开关面板,所有行为通过 profile 配置。
|
package/docs/DETAIL.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-

|
|
1
|
+

|