dsh-deepseek-webchat 0.4.10 → 0.5.0
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 +93 -29
- package/lib/client.js +425 -141
- package/lib/index.js +43 -3
- package/package.json +1 -1
- package/src/client/index.js +425 -141
- package/src/index.js +43 -3
package/lib/index.js
CHANGED
|
@@ -343,6 +343,27 @@ export function formatQuestions(questions) {
|
|
|
343
343
|
return lines.join('\n')
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Describe one tool call as prose rather than as a protocol-shaped call.
|
|
348
|
+
*
|
|
349
|
+
* The quoted text is going to be pasted into another assistant's composer, and
|
|
350
|
+
* a bare `bash({"cmd":"ls"})` reads to a model as *a function call it is being
|
|
351
|
+
* asked to continue* — it invites the other side to answer with tool-call syntax
|
|
352
|
+
* of its own, which is exactly what "do not act like an agent" is trying to
|
|
353
|
+
* avoid. So the same information is written as a sentence about something that
|
|
354
|
+
* already happened: a record, in the past tense, with the tool name in quotes
|
|
355
|
+
* and the arguments kept as data.
|
|
356
|
+
* @param name - the tool's name, as the log recorded it.
|
|
357
|
+
* @param argumentsText - its raw JSON arguments.
|
|
358
|
+
* @returns one line of readable text.
|
|
359
|
+
*/
|
|
360
|
+
export function describeToolCall(name, argumentsText) {
|
|
361
|
+
const tool = String(name ?? '').trim() === '' ? '未命名工具 / unnamed tool' : String(name).trim()
|
|
362
|
+
const args = clip(argumentsText, 800)
|
|
363
|
+
if (args === '' || args === '{}') return '当时调用了工具「' + tool + '」,没有参数。'
|
|
364
|
+
return '当时调用了工具「' + tool + '」,参数:' + args
|
|
365
|
+
}
|
|
366
|
+
|
|
346
367
|
/** Truncate long single-line payloads so a picker row stays readable. */
|
|
347
368
|
function clip(text, limit = 2000) {
|
|
348
369
|
const value = String(text ?? '').trim()
|
|
@@ -418,7 +439,9 @@ export function boundRows(rows) {
|
|
|
418
439
|
*
|
|
419
440
|
* @param events - raw events from `ctx.sessionQuery.readSession`.
|
|
420
441
|
* @param options - `{ advanced }` to include the machinery rows.
|
|
421
|
-
* @returns `{ seq, role, kind, text }` rows in log order, empty ones
|
|
442
|
+
* @returns `{ id, seq, role, kind, text }` rows in log order, empty ones
|
|
443
|
+
* dropped. `id` is unique per row; `seq` is the event it came from and is
|
|
444
|
+
* not unique (see the ordinal pass at the end).
|
|
422
445
|
*/
|
|
423
446
|
export function extractMessages(events, options = {}) {
|
|
424
447
|
if (!Array.isArray(events)) return []
|
|
@@ -451,7 +474,7 @@ export function extractMessages(events, options = {}) {
|
|
|
451
474
|
seq: event.seq,
|
|
452
475
|
role: 'assistant',
|
|
453
476
|
kind: KINDS.toolCall,
|
|
454
|
-
text: call.name
|
|
477
|
+
text: describeToolCall(call.name, call.arguments),
|
|
455
478
|
})
|
|
456
479
|
}
|
|
457
480
|
}
|
|
@@ -492,7 +515,7 @@ export function extractMessages(events, options = {}) {
|
|
|
492
515
|
if (advanced) {
|
|
493
516
|
rows.push({
|
|
494
517
|
seq: event.seq, role: 'assistant', kind: KINDS.toolCall,
|
|
495
|
-
text:
|
|
518
|
+
text: describeToolCall(event.data?.name ?? 'tool', event.data?.arguments),
|
|
496
519
|
})
|
|
497
520
|
}
|
|
498
521
|
continue
|
|
@@ -555,6 +578,23 @@ export function extractMessages(events, options = {}) {
|
|
|
555
578
|
}
|
|
556
579
|
}
|
|
557
580
|
|
|
581
|
+
// One event can yield several rows — an assistant message carries its text
|
|
582
|
+
// *and* its reasoning *and* one row per tool call — so `seq` does not
|
|
583
|
+
// identify a row. The picker ticks rows by `id` and hands it to React as the
|
|
584
|
+
// child key; keying by `seq` made the rows that share one share a checkbox
|
|
585
|
+
// (ticking any of them ticked all of them) and collide as React keys, which
|
|
586
|
+
// is what made those rows feel like they would not take a click.
|
|
587
|
+
//
|
|
588
|
+
// The ordinal is per `seq` and derived from log order, so it is stable across
|
|
589
|
+
// re-reads of the same session, and a row dropped off the front by the size
|
|
590
|
+
// cap cannot shift the ids of the rows after it.
|
|
591
|
+
const ordinals = new Map()
|
|
592
|
+
for (const row of rows) {
|
|
593
|
+
const ordinal = ordinals.get(row.seq) ?? 0
|
|
594
|
+
ordinals.set(row.seq, ordinal + 1)
|
|
595
|
+
row.id = row.seq + ':' + ordinal
|
|
596
|
+
}
|
|
597
|
+
|
|
558
598
|
return rows
|
|
559
599
|
}
|
|
560
600
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-deepseek-webchat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Embeds the official chat.deepseek.com web app in a DSH sidebar tab through the desktop shell's native browser guest, binds one DeepSeek conversation per DSH Session, and sends selected DSH context into the DeepSeek composer as a blockquote.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|