dsh-better-ask-user 0.3.6 → 0.3.8-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.
Files changed (45) hide show
  1. package/README.md +7 -7
  2. package/lib/ask-tool.d.ts +15 -0
  3. package/lib/ask-tool.js +161 -0
  4. package/lib/ask-tool.js.map +1 -0
  5. package/lib/client.js +129 -154
  6. package/lib/config.d.ts +29 -0
  7. package/lib/config.js +48 -0
  8. package/lib/config.js.map +1 -0
  9. package/lib/default-answer.d.ts +22 -0
  10. package/lib/default-answer.js +38 -0
  11. package/lib/default-answer.js.map +1 -0
  12. package/lib/index.d.ts +7 -0
  13. package/lib/index.js +48 -0
  14. package/lib/index.js.map +1 -0
  15. package/lib/ptc.d.ts +3 -0
  16. package/lib/ptc.js +13 -0
  17. package/lib/ptc.js.map +1 -0
  18. package/lib/settings.d.ts +36 -0
  19. package/lib/settings.js +81 -0
  20. package/lib/settings.js.map +1 -0
  21. package/package.json +49 -19
  22. package/src/ask-tool.js +0 -165
  23. package/src/client/AskHistoryRow.module.css +0 -26
  24. package/src/client/AskHistoryRow.tsx +0 -173
  25. package/src/client/PlanReviewPanel.module.css +0 -255
  26. package/src/client/PlanReviewPanel.tsx +0 -147
  27. package/src/client/QuestionComposer.module.css +0 -494
  28. package/src/client/QuestionComposer.tsx +0 -656
  29. package/src/client/QuestionReplyView.module.css +0 -100
  30. package/src/client/QuestionReplyView.tsx +0 -124
  31. package/src/client/QuestionWaitBar.module.css +0 -41
  32. package/src/client/QuestionWaitBar.tsx +0 -41
  33. package/src/client/contract/slots.ts +0 -650
  34. package/src/client/draft-store.ts +0 -64
  35. package/src/client/index.ts +0 -497
  36. package/src/client/locales.ts +0 -100
  37. package/src/client/question-reply.ts +0 -187
  38. package/src/client/settings-locales.ts +0 -79
  39. package/src/client/settings.module.css +0 -122
  40. package/src/client/settings.tsx +0 -336
  41. package/src/config.js +0 -54
  42. package/src/default-answer.js +0 -39
  43. package/src/index.js +0 -50
  44. package/src/ptc.js +0 -11
  45. package/src/settings.js +0 -81
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  <p align="center">
13
13
  <a href="https://www.npmjs.com/package/dsh-better-ask-user"><img src="https://img.shields.io/npm/v/dsh-better-ask-user.svg" alt="npm 版本"></a>
14
14
  <a href="LICENSE"><img alt="Apache-2.0" src="https://img.shields.io/github/license/omdsh-dev/dsh-better-ask-user?color=blue"></a>
15
- <a href="package.json"><img alt="DSH 0.2.2-rc.3" src="https://img.shields.io/badge/DSH-0.2.2--rc.3-4B32C3"></a>
15
+ <a href="package.json"><img alt="DSH 0.2.3-alpha.2" src="https://img.shields.io/badge/DSH-0.2.3--alpha.2-4B32C3"></a>
16
16
  <a href="https://github.com/omdsh-dev/dsh-better-dsh"><img alt="Part of Better DSH" src="https://img.shields.io/badge/part%20of-dsh--better--dsh-2F80B7"></a>
17
17
  </p>
18
18
 
@@ -42,7 +42,7 @@
42
42
 
43
43
  ```sh
44
44
  # 只安装这个插件
45
- dsh plugin --profile <profile> add dsh-better-ask-user@0.3.6 dsh-better-ptc@0.2.2
45
+ dsh plugin --profile <profile> add dsh-better-ask-user@0.3.8-alpha.1 dsh-better-ptc@0.2.3-alpha.1
46
46
 
47
47
  # 或安装 Better DSH(会自动带上所有独立插件)
48
48
  dsh plugin --profile <profile> add dsh-better-dsh@0.11.7
@@ -63,7 +63,7 @@ dsh plugin --profile <profile> add dsh-better-dsh@0.11.7
63
63
  | 稳定行 id | `dsh-better-ask-user` |
64
64
  | 入口 / 工具 | `ask_user_question` · 问题卡片 / 等待时间线 · 提问设置页 |
65
65
  | 设置 | 等待时长、输入续期、普通 / Goal 超时行为 |
66
- | npm 包 | `dsh-better-ask-user@0.3.6` |
66
+ | npm 包 | `dsh-better-ask-user@0.3.8-alpha.1` |
67
67
  | 仓库 | https://github.com/omdsh-dev/dsh-better-ask-user |
68
68
 
69
69
  ## 设置
@@ -83,12 +83,12 @@ dsh plugin --profile <profile> add dsh-better-dsh@0.11.7
83
83
  ## 开发
84
84
 
85
85
  ```sh
86
- npm test # 单元 / 组件测试
87
- npm run smoke # 如仓库提供运行时冒烟
86
+ npm install
87
+ npm run build # tsc 生成宿主 lib/,esbuild 生成浏览器 closure
88
+ npm run typecheck # 宿主 + 浏览器两份 tsconfig
89
+ npm test # pretest 会先构建
88
90
  ```
89
91
 
90
- 实现与测试说明见 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)。
91
-
92
92
  ## 许可
93
93
 
94
94
  [Apache License 2.0](LICENSE)。
@@ -0,0 +1,15 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
3
+ import type { AskConfig } from './config.js';
4
+ /** Model-visible notice for the native pending result. */
5
+ export declare const PENDING_QUESTION_NOTICE = "No answer batch arrived before the timeout. This is pending, not a skipped answer. Continue useful independent work. The user can still answer; their reply will be a user message identified as answer_to_pending_question with this callId and the original questions. Do not treat this as permission.";
6
+ /** Model-visible warning for a host auto-selected default batch. */
7
+ export declare const AUTO_SELECTED_WARNING = "These answers were auto-selected by the host timeout behavior, not submitted by the user. Do not treat them as user confirmation.";
8
+ /**
9
+ * Build the ask_user_question shadow from the currently registered base tool.
10
+ * @param ctx - root host context with userQuestions and optional goals.
11
+ * @param base - existing official ask_user_question definition.
12
+ * @param readConfig - live config reader.
13
+ * @returns a ToolDefinition with the official contract and the plugin wait.
14
+ */
15
+ export declare function createBetterAskTool(ctx: Context, base: ToolDefinition, readConfig: () => AskConfig): ToolDefinition;
@@ -0,0 +1,161 @@
1
+ /** ask_user_question scope shadow: official contract plus the plugin-managed wait. */
2
+ import { ToolArgsError, validateJsonSchemaValue } from '@deepseek-ai/dsh-tools';
3
+ import { TIMED_WAIT_PARAMETER } from '@deepseek-ai/dsh-user-questions';
4
+ import { buildDefaultAnswer } from './default-answer.js';
5
+ /** Model-visible notice for the native pending result. */
6
+ export const PENDING_QUESTION_NOTICE = 'No answer batch arrived before the timeout. This is pending, not a skipped answer. Continue useful independent work. The user can still answer; their reply will be a user message identified as answer_to_pending_question with this callId and the original questions. Do not treat this as permission.';
7
+ /** Model-visible warning for a host auto-selected default batch. */
8
+ export const AUTO_SELECTED_WARNING = 'These answers were auto-selected by the host timeout behavior, not submitted by the user. Do not treat them as user confirmation.';
9
+ function questionRequest(questions, exec) {
10
+ return {
11
+ questions: questions.map(question => ({
12
+ id: question.id,
13
+ question: question.question,
14
+ ...(question.header !== undefined ? { header: question.header } : {}),
15
+ ...(question.detail !== undefined ? { detail: question.detail } : {}),
16
+ ...(question.options !== undefined ? {
17
+ options: question.options.map(option => ({ ...option })),
18
+ } : {}),
19
+ ...(question.multi_select !== undefined ? { multiSelect: question.multi_select } : {}),
20
+ })),
21
+ ...(exec.agent !== undefined ? { agent: exec.agent } : {}),
22
+ signal: exec.signal,
23
+ };
24
+ }
25
+ function validateQuestionIds(questions) {
26
+ const ids = new Set();
27
+ for (const question of questions) {
28
+ if (ids.has(question.id))
29
+ throw new Error('question id ' + JSON.stringify(question.id) + ' must be unique within this call');
30
+ ids.add(question.id);
31
+ }
32
+ }
33
+ function answerResult(result) {
34
+ return {
35
+ answers: result.answers.map(answer => ({
36
+ id: answer.id,
37
+ selected: [...answer.selected],
38
+ ...(answer.custom !== undefined ? { custom: answer.custom } : {}),
39
+ })),
40
+ ...(result.autoSelected === true ? { autoSelected: true, warning: AUTO_SELECTED_WARNING } : {}),
41
+ };
42
+ }
43
+ /** Add detail and the next host marker used to replay pending questions. */
44
+ function parametersWithDetail(parameters) {
45
+ if (parameters === undefined)
46
+ return parameters;
47
+ const next = structuredClone(parameters);
48
+ // DSH classifies logged ask calls by this schema key, not by askTimed usage.
49
+ next.properties[TIMED_WAIT_PARAMETER] = {
50
+ type: 'integer',
51
+ description: 'Host continuation marker; omit. The plugin setting, not this argument, controls foreground wait duration.',
52
+ };
53
+ const properties = next?.properties?.questions?.items?.properties;
54
+ if (properties !== undefined && properties.detail === undefined) {
55
+ properties.detail = {
56
+ type: 'string',
57
+ description: 'Optional longer detail or context rendered as sanitized markdown below the question.',
58
+ };
59
+ }
60
+ return next;
61
+ }
62
+ /** Allow the additive auto-selected warning fields on the normal answer branch. */
63
+ function extendAutoSelectedSchema(schema) {
64
+ const branches = Array.isArray(schema?.oneOf) ? schema.oneOf : [schema];
65
+ for (const branch of branches) {
66
+ const properties = branch?.properties;
67
+ if (properties?.answers === undefined)
68
+ continue;
69
+ if (properties.autoSelected === undefined) {
70
+ properties.autoSelected = {
71
+ type: 'boolean',
72
+ description: 'True when the host auto-selected the default batch after the timeout; not a user answer.',
73
+ };
74
+ }
75
+ if (properties.warning === undefined) {
76
+ properties.warning = { type: 'string', description: 'Model-visible warning for an auto-selected batch.' };
77
+ }
78
+ }
79
+ return schema;
80
+ }
81
+ /** The timed path can return the official pending shape; keep it valid. */
82
+ function outputWithPending(base) {
83
+ const output = { ...base.output };
84
+ const schema = extendAutoSelectedSchema(structuredClone(base.output.schema));
85
+ if (Array.isArray(schema?.oneOf) && schema.oneOf.some(branch => branch?.properties?.pending !== undefined)) {
86
+ output.schema = schema;
87
+ return output;
88
+ }
89
+ output.schema = {
90
+ oneOf: [
91
+ schema,
92
+ {
93
+ type: 'object',
94
+ additionalProperties: false,
95
+ properties: {
96
+ pending: { type: 'boolean' },
97
+ callId: { type: 'string' },
98
+ message: { type: 'string' },
99
+ },
100
+ required: ['pending', 'callId', 'message'],
101
+ },
102
+ ],
103
+ };
104
+ return output;
105
+ }
106
+ /**
107
+ * Build the ask_user_question shadow from the currently registered base tool.
108
+ * @param ctx - root host context with userQuestions and optional goals.
109
+ * @param base - existing official ask_user_question definition.
110
+ * @param readConfig - live config reader.
111
+ * @returns a ToolDefinition with the official contract and the plugin wait.
112
+ */
113
+ export function createBetterAskTool(ctx, base, readConfig) {
114
+ const output = outputWithPending(base);
115
+ const parameters = parametersWithDetail(base.parameters);
116
+ const execute = async (input, exec) => {
117
+ const violations = validateJsonSchemaValue(parameters, input, '');
118
+ if (violations.length > 0)
119
+ throw new ToolArgsError(violations);
120
+ // The official input schema has validated this model-facing question shape.
121
+ const args = input;
122
+ validateQuestionIds(args.questions);
123
+ const userQuestions = ctx.get('userQuestions');
124
+ if (userQuestions === undefined)
125
+ throw new Error('ask_user_question requires the userQuestions service');
126
+ const config = readConfig();
127
+ const goal = exec.agent === undefined ? undefined : ctx.get('goals')?.get?.(exec.agent);
128
+ const goalActive = goal?.phase === 'active' && goal.activation === 'armed';
129
+ const mode = goalActive ? config.goalTimeoutBehavior : config.timeoutBehavior;
130
+ const seconds = config.questionTimeoutSeconds;
131
+ const questions = questionRequest(args.questions, exec);
132
+ const defaultAnswer = mode === 'default' && seconds !== -1
133
+ ? answerResult(buildDefaultAnswer(args.questions))
134
+ : undefined;
135
+ if (seconds === -1) {
136
+ const result = await userQuestions.ask({ ...questions, wait: { callId: exec.callId } });
137
+ return answerResult(result);
138
+ }
139
+ if (exec.agent === undefined)
140
+ throw new Error('timed questions require a live agent');
141
+ const waitMs = seconds * 1000;
142
+ const request = {
143
+ ...questions,
144
+ agent: exec.agent,
145
+ better: {
146
+ waitMs,
147
+ timeoutMode: mode,
148
+ ...(defaultAnswer !== undefined ? { defaultAnswer } : {}),
149
+ },
150
+ };
151
+ const result = await userQuestions.askTimed(request, exec.callId, waitMs);
152
+ if ('pending' in result) {
153
+ if (mode === 'default' && defaultAnswer !== undefined)
154
+ return answerResult(defaultAnswer);
155
+ return { ...result, message: PENDING_QUESTION_NOTICE };
156
+ }
157
+ return answerResult(result);
158
+ };
159
+ return { ...base, parameters, output, execute };
160
+ }
161
+ //# sourceMappingURL=ask-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask-tool.js","sourceRoot":"","sources":["../src/ask-tool.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;A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AAK,CAAC,sCAAsC,CAAC,CAAA;QAErF,MAAM,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;QAC7B,MAAM,OAAO,GAAwD;YACnE,GAAG,SAAS;YACZ,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE;gBACN,MAAM;gBACN,WAAW,EAAE,IAAI;gBACjB,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC1D;SACF,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACzE,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;YACxB,IAAI,IAAI,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS;gBAAE,OAAO,YAAY,CAAC,aAAa,CAAC,CAAA;YACzF,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAA;QACxD,CAAC;QACD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC,CAAA;IAED,OAAO,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;AACjD,CAAC","sourcesContent":["/** ask_user_question scope shadow: official contract plus the plugin-managed wait. */\nimport { ToolArgsError, validateJsonSchemaValue } from '@deepseek-ai/dsh-tools'\nimport { TIMED_WAIT_PARAMETER } from '@deepseek-ai/dsh-user-questions'\nimport type { Context } from '@deepseek-ai/cordis'\nimport type { JsonSchemaNode, ToolDefinition, ToolRunContext } from '@deepseek-ai/dsh-tools'\nimport type { AskUserQuestionAnswer, AskUserQuestionRequest } from '@deepseek-ai/dsh-user-questions'\nimport type { AskConfig } from './config.js'\nimport { buildDefaultAnswer } from './default-answer.js'\nimport type { ModelQuestion } from './default-answer.js'\n\n/** Model-visible notice for the native pending result. */\nexport const PENDING_QUESTION_NOTICE = 'No answer batch arrived before the timeout. This is pending, not a skipped answer. Continue useful independent work. The user can still answer; their reply will be a user message identified as answer_to_pending_question with this callId and the original questions. Do not treat this as permission.'\n\n/** Model-visible warning for a host auto-selected default batch. */\nexport const AUTO_SELECTED_WARNING = 'These answers were auto-selected by the host timeout behavior, not submitted by the user. Do not treat them as user confirmation.'\n\nfunction questionRequest(questions: ModelQuestion[], exec: ToolRunContext): AskUserQuestionRequest {\n return {\n questions: questions.map(question => ({\n id: question.id,\n question: question.question,\n ...(question.header !== undefined ? { header: question.header } : {}),\n ...(question.detail !== undefined ? { detail: question.detail } : {}),\n ...(question.options !== undefined ? {\n options: question.options.map(option => ({ ...option })),\n } : {}),\n ...(question.multi_select !== undefined ? { multiSelect: question.multi_select } : {}),\n })),\n ...(exec.agent !== undefined ? { agent: exec.agent } : {}),\n signal: exec.signal,\n }\n}\n\nfunction validateQuestionIds(questions: ModelQuestion[]) {\n const ids = new Set()\n for (const question of questions) {\n if (ids.has(question.id)) throw new Error('question id ' + JSON.stringify(question.id) + ' must be unique within this call')\n ids.add(question.id)\n }\n}\n\nfunction answerResult(result: AskUserQuestionAnswer & { autoSelected?: boolean }) {\n return {\n answers: result.answers.map(answer => ({\n id: answer.id,\n selected: [...answer.selected],\n ...(answer.custom !== undefined ? { custom: answer.custom } : {}),\n })),\n ...(result.autoSelected === true ? { autoSelected: true, warning: AUTO_SELECTED_WARNING } : {}),\n }\n}\n\n/** Add detail and the next host marker used to replay pending questions. */\nfunction parametersWithDetail(parameters: ToolDefinition['parameters']) {\n if (parameters === undefined) return parameters\n const next = structuredClone(parameters) as JsonSchemaNode & typeof parameters\n // DSH classifies logged ask calls by this schema key, not by askTimed usage.\n next.properties![TIMED_WAIT_PARAMETER] = {\n type: 'integer',\n description: 'Host continuation marker; omit. The plugin setting, not this argument, controls foreground wait duration.',\n }\n const properties = next?.properties?.questions?.items?.properties\n if (properties !== undefined && properties.detail === undefined) {\n properties.detail = {\n type: 'string',\n description: 'Optional longer detail or context rendered as sanitized markdown below the question.',\n }\n }\n return next\n}\n\n/** Allow the additive auto-selected warning fields on the normal answer branch. */\nfunction extendAutoSelectedSchema(schema: JsonSchemaNode) {\n const branches = Array.isArray(schema?.oneOf) ? schema.oneOf : [schema]\n for (const branch of branches) {\n const properties = branch?.properties\n if (properties?.answers === undefined) continue\n if (properties.autoSelected === undefined) {\n properties.autoSelected = {\n type: 'boolean',\n description: 'True when the host auto-selected the default batch after the timeout; not a user answer.',\n }\n }\n if (properties.warning === undefined) {\n properties.warning = { type: 'string', description: 'Model-visible warning for an auto-selected batch.' }\n }\n }\n return schema\n}\n\n/** The timed path can return the official pending shape; keep it valid. */\nfunction outputWithPending(base: ToolDefinition) {\n const output = { ...base.output }\n const schema = extendAutoSelectedSchema(structuredClone(base.output.schema))\n if (Array.isArray(schema?.oneOf) && schema.oneOf.some(branch => branch?.properties?.pending !== undefined)) {\n output.schema = schema\n return output\n }\n output.schema = {\n oneOf: [\n schema,\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n pending: { type: 'boolean' },\n callId: { type: 'string' },\n message: { type: 'string' },\n },\n required: ['pending', 'callId', 'message'],\n },\n ],\n }\n return output\n}\n\n/**\n * Build the ask_user_question shadow from the currently registered base tool.\n * @param ctx - root host context with userQuestions and optional goals.\n * @param base - existing official ask_user_question definition.\n * @param readConfig - live config reader.\n * @returns a ToolDefinition with the official contract and the plugin wait.\n */\nexport function createBetterAskTool(ctx: Context, base: ToolDefinition, readConfig: () => AskConfig): ToolDefinition {\n const output = outputWithPending(base)\n const parameters = parametersWithDetail(base.parameters)\n\n const execute = async (input: unknown, exec: ToolRunContext) => {\n const violations = validateJsonSchemaValue(parameters, input, '')\n if (violations.length > 0) throw new ToolArgsError(violations)\n // The official input schema has validated this model-facing question shape.\n const args = input as { questions: ModelQuestion[] }\n validateQuestionIds(args.questions)\n\n const userQuestions = ctx.get('userQuestions')\n if (userQuestions === undefined) throw new Error('ask_user_question requires the userQuestions service')\n\n const config = readConfig()\n const goal = exec.agent === undefined ? undefined : ctx.get('goals')?.get?.(exec.agent)\n const goalActive = goal?.phase === 'active' && goal.activation === 'armed'\n const mode = goalActive ? config.goalTimeoutBehavior : config.timeoutBehavior\n const seconds = config.questionTimeoutSeconds\n const questions = questionRequest(args.questions, exec)\n const defaultAnswer = mode === 'default' && seconds !== -1\n ? answerResult(buildDefaultAnswer(args.questions))\n : undefined\n\n if (seconds === -1) {\n const result = await userQuestions.ask({ ...questions, wait: { callId: exec.callId } })\n return answerResult(result)\n }\n if (exec.agent === undefined) throw new Error('timed questions require a live agent')\n\n const waitMs = seconds * 1000\n const request: Parameters<Context['userQuestions']['askTimed']>[0] = {\n ...questions,\n agent: exec.agent,\n better: {\n waitMs,\n timeoutMode: mode,\n ...(defaultAnswer !== undefined ? { defaultAnswer } : {}),\n },\n }\n const result = await userQuestions.askTimed(request, exec.callId, waitMs)\n if ('pending' in result) {\n if (mode === 'default' && defaultAnswer !== undefined) return answerResult(defaultAnswer)\n return { ...result, message: PENDING_QUESTION_NOTICE }\n }\n return answerResult(result)\n }\n\n return { ...base, parameters, output, execute }\n}"]}