@cloud411716/fancy-webnovel 1.0.9 → 1.0.10
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/index.js +65 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - File operations use Node.js fs (project roots may be outside workspace).
|
|
14
14
|
* - ctx.timer (via ctx.timeout()) handles all delays/timeouts.
|
|
15
15
|
*
|
|
16
|
-
* Required Cordis services: commands, userQuestions, timer,
|
|
16
|
+
* Required Cordis services: commands, userQuestions, timer, tools
|
|
17
17
|
* (all are part of dsh-base, so this plugin works on dsh-tui, dsh-web, dsh-desktop).
|
|
18
18
|
*
|
|
19
19
|
* IMPORTANT: This plugin needs `danger-full-access` sandbox mode because it
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import './events.js'; // documents fancy/scan:* event types (JSDoc, no runtime effect)
|
|
25
25
|
|
|
26
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
26
27
|
import { apply as applyBootstrap } from './commands/bootstrap/index.js';
|
|
27
28
|
import { apply as applyScan } from './commands/scan/index.js';
|
|
28
29
|
|
|
@@ -30,15 +31,76 @@ import { apply as applyScan } from './commands/scan/index.js';
|
|
|
30
31
|
* Services this plugin requires from the Cordis context.
|
|
31
32
|
* All are provided by dsh-base, so this works on every DSH UI.
|
|
32
33
|
*/
|
|
33
|
-
export const inject = ['commands', 'userQuestions', 'timer'];
|
|
34
|
+
export const inject = ['commands', 'userQuestions', 'timer', 'tools'];
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Called once when the plugin is loaded into a Cordis context (fiber).
|
|
37
|
-
* Registers slash commands
|
|
38
|
+
* Registers slash commands and overrides the builtin ask_user_question tool
|
|
39
|
+
* to suppress the "问卷已答" tool-result message.
|
|
38
40
|
*
|
|
39
41
|
* @param {object} ctx - Cordis plugin context
|
|
40
42
|
*/
|
|
41
43
|
export function apply(ctx) {
|
|
44
|
+
// Override the builtin ask_user_question tool so it returns null instead
|
|
45
|
+
// of { answers: [...] }, preventing DSH from appending a tool/result event
|
|
46
|
+
// (which renders as "问卷已答" in the web UI). ctx.userQuestions.ask()
|
|
47
|
+
// still works normally — only the tool result acknowledgement is suppressed.
|
|
48
|
+
ctx.tools.register(defineTool({
|
|
49
|
+
name: 'ask_user_question',
|
|
50
|
+
description: 'Ask the user a concise question when you need confirmation, a choice, or missing information before proceeding. Send one or more questions, each with a stable id that will be echoed in the answer.',
|
|
51
|
+
parameters: {
|
|
52
|
+
questions: {
|
|
53
|
+
type: 'array',
|
|
54
|
+
required: true,
|
|
55
|
+
description: 'Questions to ask the user before continuing.',
|
|
56
|
+
items: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
additionalProperties: true,
|
|
59
|
+
properties: {
|
|
60
|
+
id: { type: 'string', required: true, description: 'Stable id for this question; echoed in the answer.' },
|
|
61
|
+
question: { type: 'string', required: true, description: 'The specific question to ask the user.' },
|
|
62
|
+
header: { type: 'string', required: false, description: 'Optional short heading for the question.' },
|
|
63
|
+
options: {
|
|
64
|
+
type: 'array',
|
|
65
|
+
required: false,
|
|
66
|
+
description: 'Optional choices to show the user.',
|
|
67
|
+
items: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
additionalProperties: true,
|
|
70
|
+
properties: {
|
|
71
|
+
label: { type: 'string', required: true, description: 'Short user-facing option label.' },
|
|
72
|
+
description: { type: 'string', required: false, description: 'One sentence explaining the option.' },
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
multi_select: { type: 'boolean', required: false },
|
|
77
|
+
hideCustomInput: { type: 'boolean', required: false },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
output: {
|
|
83
|
+
// No schema: we return null, so render output is suppressed.
|
|
84
|
+
render() { return []; },
|
|
85
|
+
},
|
|
86
|
+
async execute(args, exec) {
|
|
87
|
+
await ctx.userQuestions.ask({
|
|
88
|
+
questions: args.questions.map((q) => ({
|
|
89
|
+
id: q.id,
|
|
90
|
+
question: q.question,
|
|
91
|
+
...q.header !== undefined ? { header: q.header } : {},
|
|
92
|
+
...q.options !== undefined ? { options: q.options } : {},
|
|
93
|
+
...q.multi_select !== undefined ? { multiSelect: q.multi_select } : {},
|
|
94
|
+
...q.hideCustomInput !== undefined ? { hideCustomInput: q.hideCustomInput } : {},
|
|
95
|
+
})),
|
|
96
|
+
...exec.agent !== undefined ? { agent: exec.agent } : {},
|
|
97
|
+
signal: exec.signal,
|
|
98
|
+
});
|
|
99
|
+
// Return null to suppress the tool-result acknowledgement ("问卷已答").
|
|
100
|
+
return null;
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
|
|
42
104
|
applyBootstrap(ctx);
|
|
43
105
|
applyScan(ctx);
|
|
44
106
|
}
|