dsh-context-panel 1.0.0 → 1.0.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/README.md +6 -0
- package/client.js +30 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# dsh-context-panel
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-context-panel) [](https://github.com/aloscha-elk/dsh-context-panel/blob/main/LICENSE)
|
|
4
|
+
|
|
3
5
|
**A filled context window, explained.** A DSH plugin that replaces the composer's built-in context meter with a detailed breakdown panel: how much of the model's context window is left, and what is actually taking the space.
|
|
4
6
|
|
|
5
7
|
This project authorizes [DSH Plugin](https://dsh-plugin.org/) to list this repository and display its plugin information.
|
|
6
8
|
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
_A filled context window, broken down by what is taking the space._
|
|
12
|
+
|
|
7
13
|
## What changes after installing
|
|
8
14
|
|
|
9
15
|
Clicking the `%` context meter under the message composer opens a panel with:
|
package/client.js
CHANGED
|
@@ -130,9 +130,22 @@ window.__ModuleLoader__.load({
|
|
|
130
130
|
if (block === null || typeof block !== 'object') return '';
|
|
131
131
|
if ((block.type === 'text' || block.type === 'reasoning') && typeof block.text === 'string') return block.text;
|
|
132
132
|
if (typeof block.text === 'string') return block.text;
|
|
133
|
+
// Assistant tool-call blocks carry the requested arguments as model output text.
|
|
134
|
+
if ((block.kind === 'tool-call' || block.type === 'tool-call') && typeof block.argsRaw === 'string') return block.argsRaw;
|
|
133
135
|
return '';
|
|
134
136
|
}
|
|
135
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Read one payload field from a Chat view node. The `legacy.nodes` slice stores
|
|
140
|
+
* flattened data nodes (`node.content`, `node.blocks`), while registered entries
|
|
141
|
+
* may hand over `{ kind, data }` wrappers; accept both.
|
|
142
|
+
*/
|
|
143
|
+
function nodeField(node, name) {
|
|
144
|
+
if (node !== null && typeof node === 'object' && node[name] !== undefined) return node[name];
|
|
145
|
+
const data = node?.data;
|
|
146
|
+
return data !== null && typeof data === 'object' ? data[name] : undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
136
149
|
/** Character weight of a raw argument payload, whatever shape it arrived in. */
|
|
137
150
|
function argumentsChars(value) {
|
|
138
151
|
if (typeof value === 'string') return value.length;
|
|
@@ -151,27 +164,30 @@ window.__ModuleLoader__.load({
|
|
|
151
164
|
*/
|
|
152
165
|
function nodeChars(node) {
|
|
153
166
|
const zero = { user: 0, assistant: 0, tools: 0 };
|
|
154
|
-
|
|
155
|
-
if (data === null || typeof data !== 'object') return zero;
|
|
167
|
+
if (node === null || typeof node !== 'object') return zero;
|
|
156
168
|
if (node.kind === 'user' || node.kind === 'steering' || node.kind === 'context') {
|
|
157
|
-
const content =
|
|
158
|
-
return { ...zero, user: content.reduce((sum, block) => sum + blockText(block).length, 0) };
|
|
169
|
+
const content = nodeField(node, 'content');
|
|
170
|
+
return { ...zero, user: Array.isArray(content) ? content.reduce((sum, block) => sum + blockText(block).length, 0) : 0 };
|
|
159
171
|
}
|
|
160
172
|
if (node.kind === 'assistant') {
|
|
161
|
-
const blocks =
|
|
162
|
-
return { ...zero, assistant: blocks.reduce((sum, block) => sum + blockText(block).length, 0) };
|
|
173
|
+
const blocks = nodeField(node, 'blocks');
|
|
174
|
+
return { ...zero, assistant: Array.isArray(blocks) ? blocks.reduce((sum, block) => sum + blockText(block).length, 0) : 0 };
|
|
163
175
|
}
|
|
164
176
|
if (node.kind === 'tool-result') {
|
|
165
|
-
const content =
|
|
166
|
-
const call = argumentsChars(
|
|
167
|
-
return {
|
|
177
|
+
const content = nodeField(node, 'content');
|
|
178
|
+
const call = argumentsChars(nodeField(node, 'call')?.argsRaw);
|
|
179
|
+
return {
|
|
180
|
+
...zero,
|
|
181
|
+
tools: call + (Array.isArray(content) ? content.reduce((sum, block) => sum + blockText(block).length + argumentsChars(block?.arguments), 0) : 0)
|
|
182
|
+
};
|
|
168
183
|
}
|
|
169
184
|
if (node.kind === 'tool-call') {
|
|
170
|
-
const own = argumentsChars(
|
|
171
|
-
const children =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
185
|
+
const own = argumentsChars(nodeField(node, 'argsRaw') ?? nodeField(node, 'args'));
|
|
186
|
+
const children = nodeField(node, 'subCalls');
|
|
187
|
+
return {
|
|
188
|
+
...zero,
|
|
189
|
+
tools: own + (Array.isArray(children) ? children.reduce((sum, child) => sum + nodeChars(child).tools, 0) : 0)
|
|
190
|
+
};
|
|
175
191
|
}
|
|
176
192
|
return zero;
|
|
177
193
|
}
|
package/package.json
CHANGED