@deepseek-ai/dsh-repeat-tool-reminder 0.2.0-rc.1 → 0.2.1-alpha.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.i18n.yaml +4 -4
- package/README.md +1 -2
- package/README.zh.md +1 -2
- package/lib/index.js +626 -8
- package/package.json +13 -13
package/README.i18n.yaml
CHANGED
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
en: b76a432aad14aa90
|
|
37
37
|
zh: b0cd916f7897fb42
|
|
38
38
|
/deepseek-ai-dsh-repeat-tool-reminder/understand-the-implementation/reminder-delivery:
|
|
39
|
-
en:
|
|
40
|
-
zh:
|
|
39
|
+
en: a3edc5c0f98b0d1e
|
|
40
|
+
zh: 173f6166ce3af779
|
|
41
41
|
/deepseek-ai-dsh-repeat-tool-reminder/understand-the-implementation/source-map:
|
|
42
|
-
en:
|
|
43
|
-
zh:
|
|
42
|
+
en: ba2eb423e165510d
|
|
43
|
+
zh: db5155503a8504cb
|
|
44
44
|
/deepseek-ai-dsh-repeat-tool-reminder/further-exploration:
|
|
45
45
|
en: 77b646e29c1aefa8
|
|
46
46
|
zh: f63b7df7412e524d
|
package/README.md
CHANGED
|
@@ -88,14 +88,13 @@ Each agent's chain is keyed by `(tool name, canonical arguments)` — two calls
|
|
|
88
88
|
|
|
89
89
|
### Reminder delivery
|
|
90
90
|
|
|
91
|
-
Reminders ride the post-execute decision's `additionalContexts` (source `{kind: '
|
|
91
|
+
Reminders ride the post-execute decision's `additionalContexts` (source `{kind: 'repeat-tool-reminder', form: 'notice', summary: '<tool> × <count>'}`), never a `content` replacement: the `tool/result` event stays the tool's own output for audit. The loop buffers the context and appends it as an injected `user/message` after the step's tool results, which the session renders as a plain synthetic user message — model-visible, source-attributed, and reconstructable from the session log with no new session event. The guard always delegates via `next()` and prepends its reminder to the downstream decision's context array, so both decision variants (a blocked call included) still get the nudge while every entry retains its own source and metadata.
|
|
92
92
|
|
|
93
93
|
### Source map
|
|
94
94
|
|
|
95
95
|
| File | Role |
|
|
96
96
|
|---|---|
|
|
97
97
|
| [`src/index.ts`](src/index.ts) | Plugin entry: `Config` schema, fail-loud validation, chain listeners |
|
|
98
|
-
| — | No runtime invariant companion is published; the repeat chain is private to one post-execute listener and exposes no package-owned event or snapshot that an independent companion can observe. |
|
|
99
98
|
|
|
100
99
|
</details>
|
|
101
100
|
|
package/README.zh.md
CHANGED
|
@@ -88,14 +88,13 @@ guard 建立在四项承诺之上:
|
|
|
88
88
|
|
|
89
89
|
### 提醒传递
|
|
90
90
|
|
|
91
|
-
提醒随 post-execute 决策的 `additionalContexts`(来源为 `{kind: '
|
|
91
|
+
提醒随 post-execute 决策的 `additionalContexts`(来源为 `{kind: 'repeat-tool-reminder', form: 'notice', summary: '<tool> × <count>'}`)传递,绝不替换 `content`:用于审计的 `tool/result` 事件仍保留工具自己的输出。循环会缓冲这段上下文,并在该步骤的工具结果之后作为注入的 `user/message` 追加,会话将其渲染为普通的合成用户消息——模型可见、带有来源归属,且无需新会话事件即可从会话日志重建。guard 始终通过 `next()` 委派,并把提醒放在下游决策的上下文数组之前,因此两种决策变体(包括被阻止的调用)都会收到提醒,同时每个条目保留自己的来源与元数据。
|
|
92
92
|
|
|
93
93
|
### 源码地图
|
|
94
94
|
|
|
95
95
|
| 文件 | 职责 |
|
|
96
96
|
|---|---|
|
|
97
97
|
| [`src/index.ts`](src/index.ts) | 插件入口:`Config` schema、快速失败校验、链监听器 |
|
|
98
|
-
| — | 不发布运行时不变式配套组件;重复链私有于一个 post-execute 监听器,且不公开任何可供独立配套组件观察的包自有事件或快照。 |
|
|
99
98
|
|
|
100
99
|
</details>
|
|
101
100
|
|
package/lib/index.js
CHANGED
|
@@ -162,6 +162,630 @@ function validateName(subject, value) {
|
|
|
162
162
|
if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
|
|
163
163
|
}
|
|
164
164
|
//#endregion
|
|
165
|
+
//#region ../../util/values/src/partial-json.ts
|
|
166
|
+
/**
|
|
167
|
+
* Lazily scanned view of one JSON object's top-level fields, built from text
|
|
168
|
+
* that may still be streaming or from an already parsed object. Nothing is
|
|
169
|
+
* scanned until a reader asks; the view remembers every question it answered
|
|
170
|
+
* and reports changed answers when the owner refreshes for publication.
|
|
171
|
+
* Used for model tool-call arguments: a row reads the fields it
|
|
172
|
+
* cares about at whatever granularity it displays, at every stage of the call.
|
|
173
|
+
* @module @deepseek-ai/dsh-util-values/src/partial-json
|
|
174
|
+
*/
|
|
175
|
+
const SIMPLE_ESCAPES = {
|
|
176
|
+
"\"": "\"",
|
|
177
|
+
"\\": "\\",
|
|
178
|
+
"/": "/",
|
|
179
|
+
b: "\b",
|
|
180
|
+
f: "\f",
|
|
181
|
+
n: "\n",
|
|
182
|
+
r: "\r",
|
|
183
|
+
t: " "
|
|
184
|
+
};
|
|
185
|
+
const CONTENT_ESCAPE = /[\\\u0000-\u001f]/u;
|
|
186
|
+
function isWhitespace(c) {
|
|
187
|
+
return c === " " || c === "\n" || c === "\r" || c === " ";
|
|
188
|
+
}
|
|
189
|
+
function isHex(c) {
|
|
190
|
+
return c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
191
|
+
}
|
|
192
|
+
(class PartialArguments {
|
|
193
|
+
/** The view of a call with no arguments available. */
|
|
194
|
+
static EMPTY = PartialArguments.fromObject({});
|
|
195
|
+
/**
|
|
196
|
+
* View finished argument text without scanning it until a reader asks.
|
|
197
|
+
* @param text - the complete argument JSON text.
|
|
198
|
+
* @returns a sealed view.
|
|
199
|
+
*/
|
|
200
|
+
static fromText(text) {
|
|
201
|
+
const view = new PartialArguments();
|
|
202
|
+
view.append(text);
|
|
203
|
+
view.sealed = true;
|
|
204
|
+
return view;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* View an already parsed argument payload, such as a PTC dispatch object.
|
|
208
|
+
* @param value - the parsed argument value.
|
|
209
|
+
* @returns a sealed view; a non-object payload has no fields.
|
|
210
|
+
*/
|
|
211
|
+
static fromObject(value) {
|
|
212
|
+
const view = new PartialArguments();
|
|
213
|
+
view.object = typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
214
|
+
view.sealed = true;
|
|
215
|
+
return view;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The source: text so far or a parsed object, plus whether it can still grow.
|
|
219
|
+
* These are the only enumerable fields, so two views over the same source
|
|
220
|
+
* compare equal structurally however far each has been read.
|
|
221
|
+
*/
|
|
222
|
+
chunks = [];
|
|
223
|
+
object;
|
|
224
|
+
sealed = false;
|
|
225
|
+
#ends = [];
|
|
226
|
+
#size = 0;
|
|
227
|
+
#consumed = 0;
|
|
228
|
+
#mode = "root";
|
|
229
|
+
#escape = false;
|
|
230
|
+
#keyStart = 0;
|
|
231
|
+
#keyEscaped = false;
|
|
232
|
+
#key = "";
|
|
233
|
+
#current = null;
|
|
234
|
+
#nestedEnds = [];
|
|
235
|
+
#nestedInString = false;
|
|
236
|
+
#invalidAt;
|
|
237
|
+
#invalidValue = false;
|
|
238
|
+
#entries = /* @__PURE__ */ new Map();
|
|
239
|
+
#order = [];
|
|
240
|
+
#reads = /* @__PURE__ */ new Map();
|
|
241
|
+
/** Whether this view rejects further appends; does not scan text or register reads. */
|
|
242
|
+
get isSealed() {
|
|
243
|
+
return this.sealed;
|
|
244
|
+
}
|
|
245
|
+
/** Whether indexing or a content read found invalid JSON; unread value contents are not validated. */
|
|
246
|
+
get invalid() {
|
|
247
|
+
this.scan();
|
|
248
|
+
return this.#mode === "invalid" || this.#invalidValue;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Retain streamed argument text without scanning or comparing observed answers.
|
|
252
|
+
* @param fragment - the text following every fragment appended before.
|
|
253
|
+
*/
|
|
254
|
+
append(fragment) {
|
|
255
|
+
if (this.sealed) throw new Error("PartialArguments: cannot append to a sealed view");
|
|
256
|
+
if (fragment.length === 0) return;
|
|
257
|
+
this.chunks.push(fragment);
|
|
258
|
+
this.#size += fragment.length;
|
|
259
|
+
this.#ends.push(this.#size);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Reconcile a streamed prefix with authoritative complete text without joining the fragments.
|
|
263
|
+
* @param text - the final argument text, which replaces missing or conflicting deltas.
|
|
264
|
+
* @returns this view sealed with its caches retained when every character matches; otherwise a new sealed view.
|
|
265
|
+
*/
|
|
266
|
+
settle(text) {
|
|
267
|
+
if (this.object !== void 0 || text.length !== this.#size) return PartialArguments.fromText(text);
|
|
268
|
+
let offset = 0;
|
|
269
|
+
for (const chunk of this.chunks) {
|
|
270
|
+
if (!text.startsWith(chunk, offset)) return PartialArguments.fromText(text);
|
|
271
|
+
offset += chunk.length;
|
|
272
|
+
}
|
|
273
|
+
this.chunks = text.length === 0 ? [] : [text];
|
|
274
|
+
this.#ends = text.length === 0 ? [] : [text.length];
|
|
275
|
+
this.sealed = true;
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Compare observed answers and advance their publication baseline. Unread views remain unscanned.
|
|
280
|
+
* @returns whether any observed answer changed since its first read or the preceding refresh.
|
|
281
|
+
*/
|
|
282
|
+
refresh() {
|
|
283
|
+
if (this.#reads.size === 0) return false;
|
|
284
|
+
this.scan();
|
|
285
|
+
let changed = false;
|
|
286
|
+
let completions = false;
|
|
287
|
+
for (const read of this.#reads.values()) {
|
|
288
|
+
if (read.completion) {
|
|
289
|
+
completions = true;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
changed = this.refreshRead(read) || changed;
|
|
293
|
+
}
|
|
294
|
+
if (completions) {
|
|
295
|
+
for (const read of this.#reads.values()) if (read.completion) changed = this.refreshRead(read) || changed;
|
|
296
|
+
}
|
|
297
|
+
if (this.sealed) this.#reads.clear();
|
|
298
|
+
return changed;
|
|
299
|
+
}
|
|
300
|
+
refreshRead(read) {
|
|
301
|
+
const now = read.answer();
|
|
302
|
+
if (Object.is(now, read.last)) return false;
|
|
303
|
+
read.last = now;
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Check whether no further fields can arrive.
|
|
308
|
+
* @returns whether the outer object closed, indexing failed, or the view is sealed; unread values are not validated.
|
|
309
|
+
*/
|
|
310
|
+
closed() {
|
|
311
|
+
return this.remember("closed", "", () => this.closedNow());
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* List discovered fields in first-appearance order.
|
|
315
|
+
* @returns top-level keys seen so far, in first-appearance order.
|
|
316
|
+
*/
|
|
317
|
+
keys() {
|
|
318
|
+
return this.remember("keys", "", () => this.keysNow(), (keys) => keys.length);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Check whether a top-level field has appeared.
|
|
322
|
+
* @param key - argument name.
|
|
323
|
+
* @returns whether the field has appeared (a string opened or another value began).
|
|
324
|
+
*/
|
|
325
|
+
has(key) {
|
|
326
|
+
return this.remember("has", key, () => this.hasNow(key));
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Check whether a field's closing delimiter has arrived, without validating its contents.
|
|
330
|
+
* @param key - argument name.
|
|
331
|
+
* @returns whether its delimiter arrived and no content reader has reported an error for this value.
|
|
332
|
+
*/
|
|
333
|
+
complete(key) {
|
|
334
|
+
return this.remember("complete", key, () => this.completeNow(key));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Read string length without materializing its text.
|
|
338
|
+
* @param key - argument name.
|
|
339
|
+
* @param options - change granularity for a streaming string.
|
|
340
|
+
* @returns decoded UTF-16 length of the string field so far; undefined when absent or not a string.
|
|
341
|
+
*/
|
|
342
|
+
stringLength(key, options) {
|
|
343
|
+
const step = Math.max(1, Math.floor(options?.step ?? 1));
|
|
344
|
+
const offset = options?.offset ?? 0;
|
|
345
|
+
return this.remember(`length:${step}:${offset}`, key, () => this.lengthNow(key), (length) => length === void 0 ? void 0 : Math.ceil((length + offset) / step));
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Check a string against a decoded UTF-16 length limit without materializing it.
|
|
349
|
+
* @param key - argument name.
|
|
350
|
+
* @param maxLength - decoded UTF-16 limit, floored to at least zero.
|
|
351
|
+
* @returns whether the string is longer than the limit; false when absent or not a string.
|
|
352
|
+
*/
|
|
353
|
+
stringExceeds(key, maxLength) {
|
|
354
|
+
const limit = Math.max(0, Math.floor(maxLength));
|
|
355
|
+
return this.remember(`exceeds:${limit}`, key, () => (this.lengthNow(key, limit + 1) ?? 0) > limit);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Read a decoded string, including a streaming prefix.
|
|
359
|
+
* @param key - argument name.
|
|
360
|
+
* @returns the string field's decoded text so far; undefined when absent or not a string.
|
|
361
|
+
*/
|
|
362
|
+
text(key) {
|
|
363
|
+
return this.remember("text", key, () => this.textNow(key));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Read at most the first decoded UTF-16 units of a string.
|
|
367
|
+
* @param key - argument name.
|
|
368
|
+
* @param maxLength - maximum decoded UTF-16 length, floored to at least one.
|
|
369
|
+
* @returns the bounded string prefix; undefined when absent or not a string.
|
|
370
|
+
*/
|
|
371
|
+
textPrefix(key, maxLength) {
|
|
372
|
+
const limit = Math.max(1, Math.floor(maxLength));
|
|
373
|
+
return this.remember(`prefix:${limit}`, key, () => this.textPrefixNow(key, limit));
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Read a completed non-string argument.
|
|
377
|
+
* @param key - argument name.
|
|
378
|
+
* @returns the parsed non-string value once it closed; undefined while open, absent, or a string.
|
|
379
|
+
*/
|
|
380
|
+
value(key) {
|
|
381
|
+
return this.remember("value", key, () => this.valueNow(key));
|
|
382
|
+
}
|
|
383
|
+
/** Answer a question and, on a streaming view, remember it for change detection. */
|
|
384
|
+
remember(kind, key, read, comparison) {
|
|
385
|
+
this.scan();
|
|
386
|
+
const result = read();
|
|
387
|
+
if (!this.sealed) {
|
|
388
|
+
const id = `${kind}/${key}`;
|
|
389
|
+
if (!this.#reads.has(id)) this.#reads.set(id, {
|
|
390
|
+
completion: kind === "complete",
|
|
391
|
+
answer: comparison === void 0 ? read : () => comparison(read()),
|
|
392
|
+
last: comparison === void 0 ? result : comparison(result)
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
closedNow() {
|
|
398
|
+
return this.sealed || this.#mode === "closed" || this.#mode === "invalid";
|
|
399
|
+
}
|
|
400
|
+
keysNow() {
|
|
401
|
+
return this.object === void 0 ? this.#order : Object.keys(this.object);
|
|
402
|
+
}
|
|
403
|
+
hasNow(key) {
|
|
404
|
+
return this.object === void 0 ? this.#entries.has(key) : Object.hasOwn(this.object, key);
|
|
405
|
+
}
|
|
406
|
+
completeNow(key) {
|
|
407
|
+
if (this.object !== void 0) return Object.hasOwn(this.object, key);
|
|
408
|
+
const entry = this.#entries.get(key);
|
|
409
|
+
return entry !== void 0 && entry.end >= 0 && (entry.kind === "string" ? entry.invalidAt === void 0 : !entry.invalid);
|
|
410
|
+
}
|
|
411
|
+
lengthNow(key, limit = Number.POSITIVE_INFINITY) {
|
|
412
|
+
if (this.object !== void 0) {
|
|
413
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
414
|
+
return typeof field === "string" ? field.length : void 0;
|
|
415
|
+
}
|
|
416
|
+
const entry = this.#entries.get(key);
|
|
417
|
+
if (entry?.kind !== "string") return void 0;
|
|
418
|
+
if (entry.text !== void 0 && entry.text.at === entry.end) return entry.text.length;
|
|
419
|
+
const read = entry.length ??= {
|
|
420
|
+
at: entry.start,
|
|
421
|
+
length: 0,
|
|
422
|
+
text: ""
|
|
423
|
+
};
|
|
424
|
+
this.readString(entry, read, limit, false);
|
|
425
|
+
return read.length;
|
|
426
|
+
}
|
|
427
|
+
textNow(key) {
|
|
428
|
+
if (this.object !== void 0) {
|
|
429
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
430
|
+
return typeof field === "string" ? field : void 0;
|
|
431
|
+
}
|
|
432
|
+
const entry = this.#entries.get(key);
|
|
433
|
+
if (entry?.kind !== "string") return void 0;
|
|
434
|
+
if (entry.text === void 0 && entry.end >= 0 && entry.needsDecoding && entry.invalidAt === void 0) {
|
|
435
|
+
let text;
|
|
436
|
+
try {
|
|
437
|
+
text = JSON.parse(`"${this.slice(entry.start, entry.end)}"`);
|
|
438
|
+
} catch (_error) {}
|
|
439
|
+
if (text !== void 0) entry.text = {
|
|
440
|
+
at: entry.end,
|
|
441
|
+
length: text.length,
|
|
442
|
+
text
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
const read = entry.text ??= {
|
|
446
|
+
at: entry.start,
|
|
447
|
+
length: 0,
|
|
448
|
+
text: ""
|
|
449
|
+
};
|
|
450
|
+
this.readString(entry, read, Number.POSITIVE_INFINITY, true);
|
|
451
|
+
return read.text;
|
|
452
|
+
}
|
|
453
|
+
textPrefixNow(key, maxLength) {
|
|
454
|
+
if (this.object !== void 0) {
|
|
455
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
456
|
+
return typeof field === "string" ? field.slice(0, maxLength) : void 0;
|
|
457
|
+
}
|
|
458
|
+
const entry = this.#entries.get(key);
|
|
459
|
+
if (entry?.kind !== "string") return void 0;
|
|
460
|
+
const prefixes = entry.prefixes ??= /* @__PURE__ */ new Map();
|
|
461
|
+
let read = prefixes.get(maxLength);
|
|
462
|
+
if (read === void 0) {
|
|
463
|
+
read = {
|
|
464
|
+
at: entry.start,
|
|
465
|
+
length: 0,
|
|
466
|
+
text: ""
|
|
467
|
+
};
|
|
468
|
+
prefixes.set(maxLength, read);
|
|
469
|
+
}
|
|
470
|
+
this.readString(entry, read, maxLength, true);
|
|
471
|
+
return read.text;
|
|
472
|
+
}
|
|
473
|
+
valueNow(key) {
|
|
474
|
+
if (this.object !== void 0) {
|
|
475
|
+
if (!Object.hasOwn(this.object, key)) return void 0;
|
|
476
|
+
const field = this.object[key];
|
|
477
|
+
return typeof field === "string" ? void 0 : field;
|
|
478
|
+
}
|
|
479
|
+
const entry = this.#entries.get(key);
|
|
480
|
+
if (entry?.kind !== "value" || entry.end < 0 || entry.invalid) return void 0;
|
|
481
|
+
if (entry.parsed === void 0) try {
|
|
482
|
+
entry.parsed = JSON.parse(this.slice(entry.start, entry.end));
|
|
483
|
+
} catch (_error) {
|
|
484
|
+
entry.invalid = true;
|
|
485
|
+
this.#invalidValue = true;
|
|
486
|
+
}
|
|
487
|
+
return entry.parsed;
|
|
488
|
+
}
|
|
489
|
+
chunkAt(at) {
|
|
490
|
+
let low = 0;
|
|
491
|
+
let high = this.#ends.length;
|
|
492
|
+
while (low < high) {
|
|
493
|
+
const mid = low + high >>> 1;
|
|
494
|
+
if (this.#ends[mid] <= at) low = mid + 1;
|
|
495
|
+
else high = mid;
|
|
496
|
+
}
|
|
497
|
+
return low;
|
|
498
|
+
}
|
|
499
|
+
/** Materialize only a requested range, never the cumulative source. */
|
|
500
|
+
slice(start, end) {
|
|
501
|
+
if (start >= end) return "";
|
|
502
|
+
const first = this.chunkAt(start);
|
|
503
|
+
const last = this.chunkAt(end - 1);
|
|
504
|
+
const base = first === 0 ? 0 : this.#ends[first - 1];
|
|
505
|
+
if (first === last) return this.chunks[first].slice(start - base, end - base);
|
|
506
|
+
const parts = [this.chunks[first].slice(start - base)];
|
|
507
|
+
for (let i = first + 1; i < last; i++) parts.push(this.chunks[i]);
|
|
508
|
+
parts.push(this.chunks[last].slice(0, end - this.#ends[last - 1]));
|
|
509
|
+
return parts.join("");
|
|
510
|
+
}
|
|
511
|
+
readString(entry, read, limit, materialize) {
|
|
512
|
+
const end = Math.min(entry.end < 0 ? this.#consumed : entry.end, entry.invalidAt ?? Number.POSITIVE_INFINITY, this.#invalidAt ?? Number.POSITIVE_INFINITY);
|
|
513
|
+
if (!entry.needsDecoding) {
|
|
514
|
+
const length = Math.min(end - read.at, limit - read.length);
|
|
515
|
+
if (length <= 0) return;
|
|
516
|
+
if (materialize) read.text += this.slice(read.at, read.at + length);
|
|
517
|
+
read.at += length;
|
|
518
|
+
read.length += length;
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
let chunkIndex = this.chunkAt(read.at);
|
|
522
|
+
while (read.at < end && read.length < limit) {
|
|
523
|
+
const base = chunkIndex === 0 ? 0 : this.#ends[chunkIndex - 1];
|
|
524
|
+
const chunk = this.chunks[chunkIndex];
|
|
525
|
+
const remaining = chunk.slice(read.at - base, Math.min(chunk.length, end - base));
|
|
526
|
+
const boundary = remaining.search(CONTENT_ESCAPE);
|
|
527
|
+
const length = Math.min(boundary < 0 ? remaining.length : boundary, limit - read.length);
|
|
528
|
+
if (length > 0) {
|
|
529
|
+
if (materialize) read.text += remaining.slice(0, length);
|
|
530
|
+
read.at += length;
|
|
531
|
+
read.length += length;
|
|
532
|
+
if (read.at === base + chunk.length) chunkIndex++;
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
const type = remaining.length > 1 ? remaining[1] : read.at + 1 < end ? this.chunks[chunkIndex + 1][0] : void 0;
|
|
536
|
+
let decoded;
|
|
537
|
+
let width = 2;
|
|
538
|
+
if (remaining[0] === "\\" && type === void 0 && entry.end < 0) return;
|
|
539
|
+
if (remaining[0] === "\\" && type === "u") {
|
|
540
|
+
const hex = this.slice(read.at + 2, Math.min(end, read.at + 6));
|
|
541
|
+
let valid = true;
|
|
542
|
+
for (let i = 0; i < hex.length; i++) if (!isHex(hex[i])) valid = false;
|
|
543
|
+
if (valid) {
|
|
544
|
+
if (hex.length < 4 && entry.end < 0) return;
|
|
545
|
+
if (hex.length === 4) decoded = String.fromCharCode(Number.parseInt(hex, 16));
|
|
546
|
+
}
|
|
547
|
+
width = 6;
|
|
548
|
+
} else if (remaining[0] === "\\" && type !== void 0) decoded = SIMPLE_ESCAPES[type];
|
|
549
|
+
if (decoded === void 0) {
|
|
550
|
+
entry.invalidAt = read.at;
|
|
551
|
+
this.#invalidValue = true;
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (materialize) read.text += decoded;
|
|
555
|
+
read.length++;
|
|
556
|
+
read.at += width;
|
|
557
|
+
while (chunkIndex < this.chunks.length && read.at >= this.#ends[chunkIndex]) chunkIndex++;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/** Locate new field ranges without decoding or parsing their contents. */
|
|
561
|
+
scan() {
|
|
562
|
+
if (this.object !== void 0 || this.#consumed === this.#size) return;
|
|
563
|
+
for (let i = this.chunkAt(this.#consumed); i < this.chunks.length && this.#invalidAt === void 0; i++) {
|
|
564
|
+
const pending = this.chunks[i];
|
|
565
|
+
const base = i === 0 ? 0 : this.#ends[i - 1];
|
|
566
|
+
for (let index = this.#consumed - base; index < pending.length && this.#mode !== "invalid"; index++) {
|
|
567
|
+
if (this.#mode === "string" || this.#mode === "nested" && this.#nestedInString) {
|
|
568
|
+
const end = this.stringBoundary(pending, index);
|
|
569
|
+
this.#consumed += end - index;
|
|
570
|
+
index = end;
|
|
571
|
+
if (index === pending.length) break;
|
|
572
|
+
}
|
|
573
|
+
this.step(pending[index], this.#consumed);
|
|
574
|
+
this.#consumed++;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/** Only raw quotes and their preceding backslash runs can terminate a string. */
|
|
579
|
+
stringBoundary(fragment, start) {
|
|
580
|
+
let at = start;
|
|
581
|
+
while (true) {
|
|
582
|
+
const quote = fragment.indexOf("\"", at);
|
|
583
|
+
const end = quote < 0 ? fragment.length : quote;
|
|
584
|
+
if (this.#mode === "string") {
|
|
585
|
+
const entry = this.#current;
|
|
586
|
+
if (!entry.needsDecoding && CONTENT_ESCAPE.test(fragment.slice(at, end))) entry.needsDecoding = true;
|
|
587
|
+
}
|
|
588
|
+
let slashStart = end;
|
|
589
|
+
while (slashStart > at && fragment[slashStart - 1] === "\\") slashStart--;
|
|
590
|
+
const escaped = (end - slashStart) % 2 === 1 !== (slashStart === at && this.#escape);
|
|
591
|
+
this.#escape = quote < 0 && escaped;
|
|
592
|
+
if (quote < 0 || !escaped) return end;
|
|
593
|
+
at = quote + 1;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
step(c, at) {
|
|
597
|
+
switch (this.#mode) {
|
|
598
|
+
case "root":
|
|
599
|
+
if (isWhitespace(c)) return;
|
|
600
|
+
if (c === "{") {
|
|
601
|
+
this.#mode = "key-or-end";
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
this.fail();
|
|
605
|
+
return;
|
|
606
|
+
case "key-or-end":
|
|
607
|
+
if (isWhitespace(c)) return;
|
|
608
|
+
if (c === "}") {
|
|
609
|
+
this.#mode = "closed";
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (c === "\"") {
|
|
613
|
+
this.beginKey(at);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
this.fail();
|
|
617
|
+
return;
|
|
618
|
+
case "key-only":
|
|
619
|
+
if (isWhitespace(c)) return;
|
|
620
|
+
if (c === "\"") {
|
|
621
|
+
this.beginKey(at);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
this.fail();
|
|
625
|
+
return;
|
|
626
|
+
case "key":
|
|
627
|
+
this.stepKey(c, at);
|
|
628
|
+
return;
|
|
629
|
+
case "colon":
|
|
630
|
+
if (isWhitespace(c)) return;
|
|
631
|
+
if (c === ":") {
|
|
632
|
+
this.#mode = "value";
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
this.fail();
|
|
636
|
+
return;
|
|
637
|
+
case "value":
|
|
638
|
+
this.beginValue(c, at);
|
|
639
|
+
return;
|
|
640
|
+
case "string": {
|
|
641
|
+
const entry = this.#current;
|
|
642
|
+
entry.end = at;
|
|
643
|
+
this.#current = null;
|
|
644
|
+
this.#mode = "comma-or-end";
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
case "scalar":
|
|
648
|
+
this.stepScalar(c, at);
|
|
649
|
+
return;
|
|
650
|
+
case "nested":
|
|
651
|
+
this.stepNested(c, at);
|
|
652
|
+
return;
|
|
653
|
+
case "comma-or-end":
|
|
654
|
+
if (isWhitespace(c)) return;
|
|
655
|
+
if (c === ",") {
|
|
656
|
+
this.#mode = "key-only";
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (c === "}") {
|
|
660
|
+
this.#mode = "closed";
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
this.fail();
|
|
664
|
+
return;
|
|
665
|
+
case "closed":
|
|
666
|
+
if (isWhitespace(c)) return;
|
|
667
|
+
this.fail();
|
|
668
|
+
return;
|
|
669
|
+
/* v8 ignore next 2 -- scan() stops stepping once the view is invalid. */
|
|
670
|
+
case "invalid": return;
|
|
671
|
+
/* v8 ignore next 2 -- Every scanner mode has a handler above. */
|
|
672
|
+
default: assertNever(this.#mode);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
fail() {
|
|
676
|
+
this.#invalidAt = this.#consumed;
|
|
677
|
+
this.#mode = "invalid";
|
|
678
|
+
this.#current = null;
|
|
679
|
+
}
|
|
680
|
+
beginKey(at) {
|
|
681
|
+
this.#mode = "key";
|
|
682
|
+
this.#keyStart = at + 1;
|
|
683
|
+
this.#keyEscaped = false;
|
|
684
|
+
this.#escape = false;
|
|
685
|
+
}
|
|
686
|
+
stepKey(c, at) {
|
|
687
|
+
if (c < " ") {
|
|
688
|
+
this.fail();
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (this.#escape) {
|
|
692
|
+
this.#escape = false;
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (c === "\\") {
|
|
696
|
+
this.#escape = true;
|
|
697
|
+
this.#keyEscaped = true;
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (c !== "\"") return;
|
|
701
|
+
const raw = this.slice(this.#keyStart, at);
|
|
702
|
+
if (this.#keyEscaped) try {
|
|
703
|
+
this.#key = JSON.parse(`"${raw}"`);
|
|
704
|
+
} catch (_error) {
|
|
705
|
+
this.fail();
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
else this.#key = raw;
|
|
709
|
+
this.#mode = "colon";
|
|
710
|
+
}
|
|
711
|
+
open(entry) {
|
|
712
|
+
if (!this.#entries.has(this.#key)) this.#order.push(this.#key);
|
|
713
|
+
this.#entries.set(this.#key, entry);
|
|
714
|
+
this.#current = entry;
|
|
715
|
+
}
|
|
716
|
+
beginValue(c, at) {
|
|
717
|
+
if (isWhitespace(c)) return;
|
|
718
|
+
if (c === "\"") {
|
|
719
|
+
this.open({
|
|
720
|
+
kind: "string",
|
|
721
|
+
start: at + 1,
|
|
722
|
+
end: -1,
|
|
723
|
+
needsDecoding: false,
|
|
724
|
+
invalidAt: void 0,
|
|
725
|
+
length: void 0,
|
|
726
|
+
text: void 0,
|
|
727
|
+
prefixes: void 0
|
|
728
|
+
});
|
|
729
|
+
this.#escape = false;
|
|
730
|
+
this.#mode = "string";
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (c === "}" || c === "," || c === ":" || c === "]") {
|
|
734
|
+
this.fail();
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
this.open({
|
|
738
|
+
kind: "value",
|
|
739
|
+
start: at,
|
|
740
|
+
end: -1,
|
|
741
|
+
parsed: void 0,
|
|
742
|
+
invalid: false
|
|
743
|
+
});
|
|
744
|
+
if (c === "{" || c === "[") {
|
|
745
|
+
this.#mode = "nested";
|
|
746
|
+
this.#nestedEnds = [c === "{" ? "}" : "]"];
|
|
747
|
+
this.#nestedInString = false;
|
|
748
|
+
this.#escape = false;
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
this.#mode = "scalar";
|
|
752
|
+
}
|
|
753
|
+
stepScalar(c, at) {
|
|
754
|
+
if (c !== "," && c !== "}" && !isWhitespace(c)) return;
|
|
755
|
+
this.closeValue(at);
|
|
756
|
+
this.#mode = c === "," ? "key-only" : c === "}" ? "closed" : "comma-or-end";
|
|
757
|
+
}
|
|
758
|
+
stepNested(c, at) {
|
|
759
|
+
if (this.#nestedInString) {
|
|
760
|
+
this.#nestedInString = false;
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (c === "\"") {
|
|
764
|
+
this.#nestedInString = true;
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (c === "{" || c === "[") {
|
|
768
|
+
this.#nestedEnds.push(c === "{" ? "}" : "]");
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
if (c === "}" || c === "]") {
|
|
772
|
+
if (this.#nestedEnds.pop() !== c) {
|
|
773
|
+
this.fail();
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
if (this.#nestedEnds.length === 0) {
|
|
777
|
+
this.closeValue(at + 1);
|
|
778
|
+
this.#mode = "comma-or-end";
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
closeValue(end) {
|
|
783
|
+
const entry = this.#current;
|
|
784
|
+
entry.end = end;
|
|
785
|
+
this.#current = null;
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
//#endregion
|
|
165
789
|
//#region ../../util/values/src/index.ts
|
|
166
790
|
/**
|
|
167
791
|
* Mark an unreachable closed-union branch.
|
|
@@ -284,7 +908,7 @@ const MAX_TIMER_DELAY_MS = 2147483647;
|
|
|
284
908
|
*/
|
|
285
909
|
/**
|
|
286
910
|
* Base class for all harness errors. Carries a `code` (stable, programmatic —
|
|
287
|
-
* e.g. `NO_ADAPTER`, `INVALID_ARGS
|
|
911
|
+
* e.g. `NO_ADAPTER`, `INVALID_ARGS`) distinct from the
|
|
288
912
|
* human-readable `message`, and supports `cause` chaining via the standard
|
|
289
913
|
* `ErrorOptions`. `name` defaults to the subclass constructor name.
|
|
290
914
|
*/
|
|
@@ -707,7 +1331,7 @@ function projectToolUpdates(messages, tools, toolUpdate, history) {
|
|
|
707
1331
|
/**
|
|
708
1332
|
* Centralize the non-secret product identity every provider request sends as `User-Agent`, keeping
|
|
709
1333
|
* adapters from drifting. See
|
|
710
|
-
*
|
|
1334
|
+
* `docs/subsystems/llm-streaming.md#appidentity--app-attribution`.
|
|
711
1335
|
*
|
|
712
1336
|
* App-attribution vocabulary for provider requests.
|
|
713
1337
|
* @module @deepseek-ai/dsh-llm/attribution
|
|
@@ -850,20 +1474,14 @@ var LlmError = class extends HarnessError {
|
|
|
850
1474
|
}
|
|
851
1475
|
/** Notify topology observers without letting one broken listener veto the commit. */
|
|
852
1476
|
emitAdaptersUpdated() {
|
|
853
|
-
let invariantFailure;
|
|
854
1477
|
for (const listener of this.ctx.events.dispatch("emit", ["llm/adapters-updated"])) try {
|
|
855
1478
|
const returned = listener();
|
|
856
1479
|
if (returned != null && typeof returned.then === "function") Promise.resolve(returned).then(void 0, (error) => {
|
|
857
1480
|
this.warnAdaptersListenerFailure(error);
|
|
858
1481
|
});
|
|
859
1482
|
} catch (error) {
|
|
860
|
-
if (error?.code === "INVARIANT") {
|
|
861
|
-
invariantFailure ??= error;
|
|
862
|
-
continue;
|
|
863
|
-
}
|
|
864
1483
|
this.warnAdaptersListenerFailure(error);
|
|
865
1484
|
}
|
|
866
|
-
if (invariantFailure !== void 0) throw invariantFailure;
|
|
867
1485
|
}
|
|
868
1486
|
/** Contained-listener diagnostic shared by the sync and async failure paths. */
|
|
869
1487
|
warnAdaptersListenerFailure(error) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-repeat-tool-reminder",
|
|
3
3
|
"description": "Repeat-tool-call guard plugin: advisory reminders when an agent loops on identical tool calls",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1-alpha.1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,21 +27,21 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@deepseek-ai/schemastery": "~3.18.
|
|
30
|
+
"@deepseek-ai/schemastery": "~3.18.5-alpha.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@deepseek-ai/dsh-agent": "0.2.
|
|
34
|
-
"@deepseek-ai/dsh-tools": "0.2.
|
|
35
|
-
"@deepseek-ai/cordis": "~4.0.
|
|
33
|
+
"@deepseek-ai/dsh-agent": "0.2.1-alpha.1",
|
|
34
|
+
"@deepseek-ai/dsh-tools": "0.2.1-alpha.1",
|
|
35
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@deepseek-ai/dsh-agent": "0.2.
|
|
39
|
-
"@deepseek-ai/dsh-agent-loop": "0.2.
|
|
40
|
-
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.
|
|
41
|
-
"@deepseek-ai/dsh-llm": "0.2.
|
|
42
|
-
"@deepseek-ai/dsh-session": "0.2.
|
|
43
|
-
"@deepseek-ai/dsh-tools": "0.2.
|
|
44
|
-
"@deepseek-ai/cordis": "~4.0.
|
|
45
|
-
"@deepseek-ai/dsh-session-projection": "0.2.
|
|
38
|
+
"@deepseek-ai/dsh-agent": "0.2.1-alpha.1",
|
|
39
|
+
"@deepseek-ai/dsh-agent-loop": "0.2.1-alpha.1",
|
|
40
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.1-alpha.1",
|
|
41
|
+
"@deepseek-ai/dsh-llm": "0.2.1-alpha.1",
|
|
42
|
+
"@deepseek-ai/dsh-session": "0.2.1-alpha.1",
|
|
43
|
+
"@deepseek-ai/dsh-tools": "0.2.1-alpha.1",
|
|
44
|
+
"@deepseek-ai/cordis": "~4.0.5-alpha.1",
|
|
45
|
+
"@deepseek-ai/dsh-session-projection": "0.2.1-alpha.1"
|
|
46
46
|
}
|
|
47
47
|
}
|