dsh-ntr 0.3.2 → 0.3.3

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/lib/index.js CHANGED
@@ -216,6 +216,33 @@ export function apply(ctx, config) {
216
216
  wireAcpMode();
217
217
  });
218
218
  }
219
+ const wireAttachments = (injectedCtx) => {
220
+ const c = injectedCtx ?? ctx;
221
+ let attachments;
222
+ try {
223
+ if (typeof c.get === 'function') {
224
+ attachments = c.get('attachments') ?? c.get('attachmentService');
225
+ }
226
+ }
227
+ catch { }
228
+ try {
229
+ if (attachments === undefined) {
230
+ attachments = c.attachments ?? c.attachmentService;
231
+ }
232
+ }
233
+ catch { }
234
+ if (attachments !== undefined) {
235
+ manager.setAttachmentResolver(attachments);
236
+ }
237
+ else {
238
+ manager.setAttachmentResolver(c);
239
+ }
240
+ };
241
+ wireAttachments();
242
+ if (typeof ctx.inject === 'function') {
243
+ ctx.inject(['attachments'], injectedCtx => { wireAttachments(injectedCtx); });
244
+ ctx.inject(['attachmentService'], injectedCtx => { wireAttachments(injectedCtx); });
245
+ }
219
246
  const registerLlm = (llmHandle) => {
220
247
  ctx.effect(() => {
221
248
  // The route exists so the host's driver can reach this adapter at all:
package/lib/tps.js ADDED
@@ -0,0 +1,32 @@
1
+ /** ACP `usage_update` is context occupancy, not request tokens; this is the plugin's 4-chars/token OUTPUT estimate (tool args excluded). */
2
+ export const OUTPUT_CHARS_PER_TOKEN = 4;
3
+ export const BURST_GAP_MS = 1000;
4
+ export class TurnTpsTracker {
5
+ gapMs;
6
+ lastProseAt;
7
+ outputChars = 0;
8
+ burstMs = 0;
9
+ constructor(gapMs = BURST_GAP_MS) {
10
+ this.gapMs = gapMs;
11
+ }
12
+ onProse(text, at) {
13
+ if (text === '')
14
+ return;
15
+ if (this.lastProseAt !== undefined) {
16
+ const gap = at - this.lastProseAt;
17
+ if (gap <= this.gapMs)
18
+ this.burstMs += gap;
19
+ }
20
+ this.lastProseAt = at;
21
+ this.outputChars += text.length;
22
+ }
23
+ onBreak() {
24
+ this.lastProseAt = undefined;
25
+ }
26
+ snapshot() {
27
+ return {
28
+ outputTokens: Math.round(this.outputChars / OUTPUT_CHARS_PER_TOKEN),
29
+ burstMs: this.burstMs,
30
+ };
31
+ }
32
+ }