dsh-better-ask-user 0.3.6 → 0.3.7-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 +1 -0
  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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAAA;AAC/C,MAAM,CAAC,MAAM,MAAM,GAAG,qBAAqB,CAAA;AAC3C,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAA;AACnD,MAAM,OAAO,GAAG,IAAI,CAAA;AACpB,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAE3B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;AAEvF,SAAS,MAAM,CAAC,KAAc,EAAE,GAAgB;IAC9C,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AACjF,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,OAAwB,EAAE,EAAU;IAC5D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAA;QACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,SAAS,CAAA;QAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAY,EAAE,EAAE,CAAE,GAA2C,EAAE,EAAE,KAAK,EAAE,CAAmC,CAAA;IAC/H,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,C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,GAAY;IAC/C,GAAG,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;QACjC,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAA;QACvC,KAAK,4BAA4B,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACzD,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,0DAA0D,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QAClG,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["/** Use the custom browser settings page and migrate the legacy goal wait. */\nimport type { Context } from '@deepseek-ai/cordis'\n\ninterface SettingsDescriptor {\n ns: string\n user?: Record<string, unknown> | null\n value?: Record<string, unknown> | null\n revision?: unknown\n}\n\nexport interface SettingsService {\n writable?: boolean\n describe(): unknown | Promise<unknown>\n update(ns: string, patch: { questionTimeoutSeconds: number }, revision: unknown): unknown | Promise<unknown>\n}\n\nexport const LEGACY_GOAL_NS = 'dsh-better-goal'\nexport const ASK_NS = 'dsh-better-ask-user'\nexport const MAX_QUESTION_TIMEOUT_SECONDS = 2147483\nconst WAIT_MS = 3000\nconst WAIT_INTERVAL_MS = 50\n\nconst sleep = (ms: number) => new Promise<void>(resolve => { setTimeout(resolve, ms) })\n\nfunction hasOwn(value: unknown, key: PropertyKey) {\n return value !== null && typeof value === 'object' && Object.hasOwn(value, key)\n}\n\nasync function descriptor(service: SettingsService, ns: string): Promise<SettingsDescriptor | undefined> {\n try {\n const rows = await service.describe()\n if (!Array.isArray(rows)) return undefined\n return rows.find((row: unknown) => (row as { ns?: unknown } | null | undefined)?.ns === ns) as SettingsDescriptor | undefined\n } catch {\n return undefined\n }\n}\n\nfunction validSeconds(value: unknown): value is number {\n return value === -1 || (typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= MAX_QUESTION_TIMEOUT_SECONDS)\n}\n\n/**\n * Copy an explicit legacy dsh-better-goal questionTimeoutSeconds into this\n * row's questionTimeoutSeconds. The target's explicit value always wins; the\n * source's default 120 is not treated as a custom value. Safe to repeat.\n * @param service - settings service with describe / update.\n * @returns a status report.\n */\nexport async function migrateLegacyQuestionTimeout(service: Partial<SettingsService> | null | undefined) {\n if (typeof service?.describe !== 'function' || typeof service?.update !== 'function') {\n return { status: 'unavailable' }\n }\n const deadline = Date.now() + WAIT_MS\n let source = await descriptor(service as SettingsService, LEGACY_GOAL_NS)\n let target = await descriptor(service as SettingsService, ASK_NS)\n while ((source === undefined || target === undefined) && Date.now() < deadline) {\n await sleep(WAIT_INTERVAL_MS)\n source = await descriptor(service as SettingsService, LEGACY_GOAL_NS)\n target = await descriptor(service as SettingsService, ASK_NS)\n }\n if (source === undefined || target === undefined) return { status: 'pending' }\n if (!hasOwn(source.user, 'questionTimeoutSeconds')) return { status: 'no-change' }\n if (hasOwn(target.user, 'questionTimeoutSeconds')) return { status: 'no-change' }\n const value = source.value?.questionTimeoutSeconds\n if (!validSeconds(value)) return { status: 'no-change' }\n if (service.writable === false) return { status: 'pending' }\n try {\n await service.update(ASK_NS, { questionTimeoutSeconds: value }, target.revision)\n } catch (error) {\n return { status: 'error', error: error instanceof Error ? error.message : String(error) }\n }\n const after = await descriptor(service as SettingsService, ASK_NS)\n return after?.user?.questionTimeoutSeconds === value\n ? { status: 'complete', value }\n : { status: 'pending', value }\n}\n\n/** Use the custom browser settings page instead of a generated form. */\nexport function mountSettings(ctx: Context) {\n ctx.inject(['settings'], (inner) => {\n const dispose = inner.settings.configure({ auto: false }, ctx.fiber)\n inner.effect(() => dispose, 'better-ask-user: settings page')\n })\n}\n\n/** Run the legacy goal-wait migration once the settings service is available. */\nexport function mountLegacyMigration(ctx: Context) {\n ctx.inject(['settings'], (inner) => {\n const service = inner.settings ?? inner\n void migrateLegacyQuestionTimeout(service).catch((error) => {\n inner.logger?.warn?.('better-ask-user: legacy question wait migration failed: ' + String(error))\n })\n })\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-ask-user",
3
- "version": "0.3.6",
3
+ "version": "0.3.7-alpha.1",
4
4
  "description": "Independent ask_user_question plugin: configurable wait, input-extended countdown, markdown/mobile card, native or default timeout behavior, and PTC deadline exemption.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,41 +8,70 @@
8
8
  "url": "git+https://github.com/omdsh-dev/dsh-better-ask-user.git"
9
9
  },
10
10
  "type": "module",
11
- "main": "src/index.js",
11
+ "main": "lib/index.js",
12
+ "types": "lib/index.d.ts",
12
13
  "exports": {
13
- ".": "./src/index.js",
14
+ ".": {
15
+ "types": "./lib/index.d.ts",
16
+ "default": "./lib/index.js"
17
+ },
14
18
  "./client": "./lib/client.js",
15
19
  "./package.json": "./package.json"
16
20
  },
17
21
  "engines": {
18
- "node": ">=24.9.0",
19
- "dsh": ">=0.2.2-rc.2 <0.3.0"
22
+ "node": "^24.22.3 || >=26.13.1",
23
+ "dsh": ">=0.2.3-alpha.2 <0.3.0"
20
24
  },
21
25
  "scripts": {
22
- "pretest": "node scripts/build-client.mjs",
26
+ "build": "tsc -p tsconfig.build.json && node scripts/build-client.mjs",
27
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.client.json",
28
+ "pretest": "npm run build",
23
29
  "test": "node --test",
24
- "build": "node scripts/build-client.mjs"
30
+ "prepare": "npm run build"
25
31
  },
26
32
  "dependencies": {
27
- "@deepseek-ai/schemastery": "~3.19.0",
28
- "dsh-better-ptc": "0.2.2"
33
+ "@deepseek-ai/schemastery": "~3.20.0-alpha.1",
34
+ "dsh-better-ptc": "0.2.3-alpha.1"
29
35
  },
30
36
  "peerDependencies": {
31
- "@deepseek-ai/cordis": "~4.1.0",
32
- "@deepseek-ai/dsh-agent": ">=0.2.2-rc.2 <0.3.0",
33
- "@deepseek-ai/dsh-llm": ">=0.2.2-rc.2 <0.3.0",
34
- "@deepseek-ai/dsh-session": ">=0.2.2-rc.2 <0.3.0",
35
- "@deepseek-ai/dsh-system-prompt": ">=0.2.2-rc.2 <0.3.0",
36
- "@deepseek-ai/dsh-tools": ">=0.2.2-rc.2 <0.3.0",
37
- "@deepseek-ai/dsh-user-questions": ">=0.2.2-rc.2 <0.3.0",
37
+ "@deepseek-ai/cordis": "~4.2.0-alpha.1",
38
+ "@deepseek-ai/dsh-agent": ">=0.2.3-alpha.2 <0.3.0",
39
+ "@deepseek-ai/dsh-llm": ">=0.2.3-alpha.2 <0.3.0",
40
+ "@deepseek-ai/dsh-session": ">=0.2.3-alpha.2 <0.3.0",
41
+ "@deepseek-ai/dsh-system-prompt": ">=0.2.3-alpha.2 <0.3.0",
42
+ "@deepseek-ai/dsh-tools": ">=0.2.3-alpha.2 <0.3.0",
43
+ "@deepseek-ai/dsh-user-questions": ">=0.2.3-alpha.2 <0.3.0",
38
44
  "react": "^18.2.0"
39
45
  },
40
46
  "devDependencies": {
47
+ "@deepseek-ai/cordis": "4.2.0-alpha.1",
48
+ "@deepseek-ai/dsh-agent": "0.2.3-alpha.2",
49
+ "@deepseek-ai/dsh-api-remotes": "0.2.3-alpha.2",
50
+ "@deepseek-ai/dsh-api-session-controller": "0.2.3-alpha.2",
51
+ "@deepseek-ai/dsh-brand": "0.2.3-alpha.2",
52
+ "@deepseek-ai/dsh-client-locale": "0.2.3-alpha.2",
53
+ "@deepseek-ai/dsh-client-store": "0.2.3-alpha.2",
54
+ "@deepseek-ai/dsh-client-ui-chat": "0.2.3-alpha.2",
55
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.3-alpha.2",
56
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.3-alpha.2",
57
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.3-alpha.2",
58
+ "@deepseek-ai/dsh-client-ui-session": "0.2.3-alpha.2",
59
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.3-alpha.2",
60
+ "@deepseek-ai/dsh-client-ui-tool": "0.2.3-alpha.2",
61
+ "@deepseek-ai/dsh-llm": "0.2.3-alpha.2",
62
+ "@deepseek-ai/dsh-session": "0.2.3-alpha.2",
63
+ "@deepseek-ai/dsh-system-prompt": "0.2.3-alpha.2",
64
+ "@deepseek-ai/dsh-tools": "0.2.3-alpha.2",
65
+ "@deepseek-ai/dsh-typert-protocol": "0.2.3-alpha.2",
66
+ "@deepseek-ai/dsh-user-questions": "0.2.3-alpha.2",
67
+ "@types/node": "24.19.2",
68
+ "@types/react": "18.3.31",
41
69
  "clsx": "^2.1.1",
42
70
  "esbuild": "^0.25.0",
43
71
  "js-yaml": "^4.2.0",
44
72
  "react": "18.3.1",
45
- "react-test-renderer": "18.3.1"
73
+ "react-test-renderer": "18.3.1",
74
+ "typescript": "5.9.3"
46
75
  },
47
76
  "dsh": {
48
77
  "bundle": {
@@ -62,8 +91,9 @@
62
91
  }
63
92
  },
64
93
  "files": [
65
- "src",
66
- "lib/client.js",
94
+ "lib/**/*.js",
95
+ "lib/**/*.d.ts",
96
+ "lib/**/*.js.map",
67
97
  "cordis.patch.yml",
68
98
  "README.md",
69
99
  "LICENSE",
package/src/ask-tool.js DELETED
@@ -1,165 +0,0 @@
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
-
6
- /** Model-visible notice for the native pending result. */
7
- 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.'
8
-
9
- /** Model-visible warning for a host auto-selected default batch. */
10
- 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.'
11
-
12
- function questionRequest(questions, exec) {
13
- return {
14
- questions: questions.map(question => ({
15
- id: question.id,
16
- question: question.question,
17
- ...(question.header !== undefined ? { header: question.header } : {}),
18
- ...(question.detail !== undefined ? { detail: question.detail } : {}),
19
- ...(question.options !== undefined ? {
20
- options: question.options.map(option => ({ ...option })),
21
- } : {}),
22
- ...(question.multi_select !== undefined ? { multiSelect: question.multi_select } : {}),
23
- })),
24
- ...(exec.agent !== undefined ? { agent: exec.agent } : {}),
25
- signal: exec.signal,
26
- }
27
- }
28
-
29
- function validateQuestionIds(questions) {
30
- const ids = new Set()
31
- for (const question of questions) {
32
- if (ids.has(question.id)) throw new Error('question id ' + JSON.stringify(question.id) + ' must be unique within this call')
33
- ids.add(question.id)
34
- }
35
- }
36
-
37
- function answerResult(result) {
38
- return {
39
- answers: result.answers.map(answer => ({
40
- id: answer.id,
41
- selected: [...answer.selected],
42
- ...(answer.custom !== undefined ? { custom: answer.custom } : {}),
43
- })),
44
- ...(result.autoSelected === true ? { autoSelected: true, warning: AUTO_SELECTED_WARNING } : {}),
45
- }
46
- }
47
-
48
- /** Add detail and the next host marker used to replay pending questions. */
49
- function parametersWithDetail(parameters) {
50
- if (parameters === undefined) return parameters
51
- const next = structuredClone(parameters)
52
- // DSH classifies logged ask calls by this schema key, not by askTimed usage.
53
- next.properties[TIMED_WAIT_PARAMETER] = {
54
- type: 'integer',
55
- description: 'Host continuation marker; omit. The plugin setting, not this argument, controls foreground wait duration.',
56
- }
57
- const properties = next?.properties?.questions?.items?.properties
58
- if (properties !== undefined && properties.detail === undefined) {
59
- properties.detail = {
60
- type: 'string',
61
- description: 'Optional longer detail or context rendered as sanitized markdown below the question.',
62
- }
63
- }
64
- return next
65
- }
66
-
67
- /** Allow the additive auto-selected warning fields on the normal answer branch. */
68
- function extendAutoSelectedSchema(schema) {
69
- const branches = Array.isArray(schema?.oneOf) ? schema.oneOf : [schema]
70
- for (const branch of branches) {
71
- const properties = branch?.properties
72
- if (properties?.answers === undefined) continue
73
- if (properties.autoSelected === undefined) {
74
- properties.autoSelected = {
75
- type: 'boolean',
76
- description: 'True when the host auto-selected the default batch after the timeout; not a user answer.',
77
- }
78
- }
79
- if (properties.warning === undefined) {
80
- properties.warning = { type: 'string', description: 'Model-visible warning for an auto-selected batch.' }
81
- }
82
- }
83
- return schema
84
- }
85
-
86
- /** The timed path can return the official pending shape; keep it valid. */
87
- function outputWithPending(base) {
88
- const output = { ...base.output }
89
- const schema = extendAutoSelectedSchema(structuredClone(base.output.schema))
90
- if (Array.isArray(schema?.oneOf) && schema.oneOf.some(branch => branch?.properties?.pending !== undefined)) {
91
- output.schema = schema
92
- return output
93
- }
94
- output.schema = {
95
- oneOf: [
96
- schema,
97
- {
98
- type: 'object',
99
- additionalProperties: false,
100
- properties: {
101
- pending: { type: 'boolean' },
102
- callId: { type: 'string' },
103
- message: { type: 'string' },
104
- },
105
- required: ['pending', 'callId', 'message'],
106
- },
107
- ],
108
- }
109
- return output
110
- }
111
-
112
- /**
113
- * Build the ask_user_question shadow from the currently registered base tool.
114
- * @param ctx - root host context with userQuestions and optional goals.
115
- * @param base - existing official ask_user_question definition.
116
- * @param readConfig - live config reader.
117
- * @returns a ToolDefinition with the official contract and the plugin wait.
118
- */
119
- export function createBetterAskTool(ctx, base, readConfig) {
120
- const output = outputWithPending(base)
121
- const parameters = parametersWithDetail(base.parameters)
122
-
123
- const execute = async (args, exec) => {
124
- const violations = validateJsonSchemaValue(parameters, args, '')
125
- if (violations.length > 0) throw new ToolArgsError(violations)
126
- validateQuestionIds(args.questions)
127
-
128
- const userQuestions = ctx.get('userQuestions')
129
- if (userQuestions === undefined) throw new Error('ask_user_question requires the userQuestions service')
130
-
131
- const config = readConfig()
132
- const goal = exec.agent === undefined ? undefined : ctx.get('goals')?.get?.(exec.agent)
133
- const goalActive = goal?.phase === 'active' && goal.activation === 'armed'
134
- const mode = goalActive ? config.goalTimeoutBehavior : config.timeoutBehavior
135
- const seconds = config.questionTimeoutSeconds
136
- const questions = questionRequest(args.questions, exec)
137
- const defaultAnswer = mode === 'default' && seconds !== -1
138
- ? answerResult(buildDefaultAnswer(args.questions))
139
- : undefined
140
-
141
- if (seconds === -1) {
142
- const result = await userQuestions.ask({ ...questions, wait: { callId: exec.callId } })
143
- return answerResult(result)
144
- }
145
- if (exec.agent === undefined) throw new Error('timed questions require a live agent')
146
-
147
- const waitMs = seconds * 1000
148
- const result = await userQuestions.askTimed({
149
- ...questions,
150
- agent: exec.agent,
151
- better: {
152
- waitMs,
153
- timeoutMode: mode,
154
- ...(defaultAnswer !== undefined ? { defaultAnswer } : {}),
155
- },
156
- }, exec.callId, waitMs)
157
- if ('pending' in result) {
158
- if (mode === 'default' && defaultAnswer !== undefined) return answerResult(defaultAnswer)
159
- return { ...result, message: PENDING_QUESTION_NOTICE }
160
- }
161
- return answerResult(result)
162
- }
163
-
164
- return { ...base, parameters, output, execute }
165
- }
@@ -1,26 +0,0 @@
1
- .frame {
2
- --cfg-line: var(--dsw-alias-border-l2);
3
- --cfg-ink: var(--dsw-alias-label-primary);
4
- --cfg-muted: var(--dsw-alias-label-secondary);
5
- --cfg-accent: var(--dsw-alias-state-business-primary, #3388bb);
6
- --cfg-accent-text: color-mix(in srgb, var(--cfg-accent) 70%, var(--cfg-ink));
7
- --cfg-hover: var(--dsw-alias-interactive-bg-hover);
8
- min-width: 0;
9
- }
10
- .row { appearance: none; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; min-width: 0; padding: 4px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--cfg-muted); font: inherit; line-height: 20px; text-align: left; }
11
- button.row { cursor: pointer; }
12
- button.row:hover { background: var(--cfg-hover); color: var(--cfg-ink); }
13
- button.row:active { background: color-mix(in srgb, var(--cfg-accent) 9%, transparent); }
14
- button.row:focus-visible { outline: 2px solid var(--cfg-accent); outline-offset: -2px; }
15
- .icon { display: inline-flex; flex: none; color: var(--dsw-alias-label-tertiary); }
16
- .icon svg { width: 14px; height: 14px; }
17
- .summary { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
18
- .open { display: inline-flex; align-items: center; gap: 4px; flex: none; color: var(--cfg-muted); font-size: 12px; }
19
- .state { flex: none; color: var(--dsw-alias-label-tertiary); font-size: 12px; }
20
- .error { display: block; padding: 4px 8px 4px 30px; color: var(--dsw-alias-state-error-primary); font-size: 12px; line-height: 18px; overflow-wrap: anywhere; }
21
- @media (max-width: 640px) { .row { min-height: 44px; align-items: flex-start; padding-block: 10px; } .summary { white-space: normal; overflow-wrap: anywhere; } .open { align-self: center; } }
22
- @media (pointer: coarse) { .row { min-height: 44px; } }
23
- @media (prefers-reduced-motion: reduce) { button.row { transition: none; } }
24
-
25
- [data-ds-dark-theme] .frame { --cfg-accent: var(--dsw-alias-state-business-primary, #4eb0e8); --cfg-accent-text: color-mix(in srgb, var(--cfg-accent) 70%, var(--cfg-ink)); }
26
-
@@ -1,173 +0,0 @@
1
- /** History row for ask_user_question: compact summary plus a live or review action. */
2
- import { useState } from 'react'
3
- import { IconChevronRightOutlineRegular, IconQuestionOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives'
4
- import type { HostObservable, InjectFace, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
5
- import type { ToolCallViewProps, UserQuestionRecord } from '@deepseek-ai/dsh-client-ui-tool/client'
6
- import type { AskUserQuestionItem } from '@deepseek-ai/dsh-user-questions/types'
7
- import css from './AskHistoryRow.module.css'
8
-
9
- type AskHistoryRowProps = ToolCallViewProps & PropsLocale<'question'> & InjectFace<{
10
- revealPanel: (callId: string) => boolean
11
- reviewPanel: (callId: string, record: UserQuestionRecord) => boolean
12
- keyedHooks: { questionPanelLive: (callId: string) => HostObservable<boolean> }
13
- }>
14
-
15
- interface AnswerEntry {
16
- id: string
17
- selected: string[]
18
- custom?: string
19
- }
20
-
21
- function isRecord(value: unknown): value is Record<string, unknown> {
22
- return typeof value === 'object' && value !== null && !Array.isArray(value)
23
- }
24
-
25
- function parseJson(text: string): unknown {
26
- try {
27
- return JSON.parse(text)
28
- } catch {
29
- return undefined
30
- }
31
- }
32
-
33
- function resultText(content: readonly unknown[]): string | undefined {
34
- const parts: string[] = []
35
- for (const block of content) {
36
- if (!isRecord(block) || block.type !== 'text' || typeof block.text !== 'string') continue
37
- parts.push(block.text)
38
- }
39
- return parts.length === 0 ? undefined : parts.join('\n')
40
- }
41
-
42
- function questionList(argsRaw: string): AskUserQuestionItem[] | undefined {
43
- const parsed = parseJson(argsRaw)
44
- if (!isRecord(parsed) || !Array.isArray(parsed.questions) || parsed.questions.length === 0) return undefined
45
- const questions: AskUserQuestionItem[] = []
46
- for (const candidate of parsed.questions) {
47
- if (!isRecord(candidate) || typeof candidate.id !== 'string' || typeof candidate.question !== 'string') return undefined
48
- questions.push({
49
- id: candidate.id,
50
- question: candidate.question,
51
- ...(typeof candidate.header === 'string' ? { header: candidate.header } : {}),
52
- ...(typeof candidate.detail === 'string' ? { detail: candidate.detail } : {}),
53
- ...(Array.isArray(candidate.options)
54
- ? {
55
- options: candidate.options.flatMap(option => isRecord(option) && typeof option.label === 'string'
56
- ? [{
57
- label: option.label,
58
- ...(typeof option.description === 'string' ? { description: option.description } : {}),
59
- }]
60
- : []),
61
- }
62
- : {}),
63
- ...(typeof candidate.multi_select === 'boolean' ? { multiSelect: candidate.multi_select } : {}),
64
- })
65
- }
66
- return questions
67
- }
68
-
69
- function answerList(text: string | undefined): AnswerEntry[] | undefined {
70
- if (text === undefined) return undefined
71
- const parsed = parseJson(text)
72
- if (!isRecord(parsed) || !Array.isArray(parsed.answers)) return undefined
73
- const answers: AnswerEntry[] = []
74
- for (const candidate of parsed.answers) {
75
- if (!isRecord(candidate)
76
- || typeof candidate.id !== 'string'
77
- || !Array.isArray(candidate.selected)
78
- || !candidate.selected.every(value => typeof value === 'string')
79
- || (candidate.custom !== undefined && typeof candidate.custom !== 'string')) return undefined
80
- answers.push({
81
- id: candidate.id,
82
- selected: candidate.selected,
83
- ...(candidate.custom === undefined ? {} : { custom: candidate.custom }),
84
- })
85
- }
86
- return answers
87
- }
88
-
89
- /**
90
- * The compact history re-entry for one ask call, top-level or nested.
91
- *
92
- * The action follows what is actually reachable, not a guess from the result
93
- * shape: a card still in the plugin registry opens the live panel, and a
94
- * settled call opens a read-only review built from its recorded answers. A
95
- * finished question therefore stays inspectable even when it recorded no
96
- * answers, and never offers a reopen that cannot succeed.
97
- */
98
- export function AskHistoryRow({
99
- callId,
100
- block,
101
- phase,
102
- useProjection,
103
- useQuestionPanelLive,
104
- revealPanel,
105
- reviewPanel,
106
- t,
107
- }: AskHistoryRowProps): React.JSX.Element {
108
- const [failedAction, setFailedAction] = useState<string | null>(null)
109
- const argsRaw = 'kind' in block ? block.call?.argsRaw ?? '' : 'argsRaw' in block ? block.argsRaw : ''
110
- const output = 'kind' in block ? resultText(block.content) : undefined
111
- const questions = questionList(argsRaw)
112
- // A late reply settles through the projection, not through a second tool result.
113
- const settled = useProjection('userQuestions', view => view?.settled.find(row => row.callId === callId))
114
- const answers = settled?.answers ?? answerList(output) ?? []
115
- const live = useQuestionPanelLive(callId, present => present === true)
116
- const errorCode = 'kind' in block ? block.error?.code : undefined
117
- // Every settled call with readable questions can be reviewed; an empty answer
118
- // batch still shows the question and its "no answer recorded" state. The
119
- // review is read-only, so an interrupted call must never expose "Open".
120
- const record: UserQuestionRecord | undefined = questions !== undefined && phase === 'result'
121
- ? { questions, answers }
122
- : undefined
123
- // A live card is the truth; a terminal label belongs only to the settled view.
124
- // Before the client card arrives, keep the row honest: it is waiting for the
125
- // question UI rather than silently offering nothing.
126
- const status = live
127
- ? undefined
128
- : errorCode === 'ASK_ABORTED' || errorCode === 'interrupted'
129
- ? t('history.interrupted')
130
- : errorCode === 'ASK_CANCELLED'
131
- ? t('history.cancelled')
132
- : phase === 'start'
133
- ? t('history.waiting')
134
- : undefined
135
- const summary = questions?.[0]?.question.split('\n').find(line => line.trim() !== '')?.trim() ?? t('history.title')
136
- const action = live
137
- ? () => revealPanel(callId)
138
- : record === undefined
139
- ? undefined
140
- : () => reviewPanel(callId, record)
141
- const review = !live && record !== undefined
142
- const actionKey = `${callId}-${review ? 'review' : 'open'}`
143
- const actionLabel = review ? t('history.review') : t('history.reopen')
144
-
145
- const trailing = action === undefined
146
- ? status === undefined ? null : <span className={css.state}>{status}</span>
147
- : (
148
- <span className={css.open}>
149
- {status !== undefined && <span className={css.state}>{status}</span>}
150
- {actionLabel}<IconChevronRightOutlineRegular size={14} />
151
- </span>
152
- )
153
-
154
- const content = (
155
- <>
156
- <span className={css.icon} aria-hidden="true"><IconQuestionOutlineRegular /></span>
157
- <span className={css.summary} title={summary}>{summary}</span>
158
- {trailing}
159
- </>
160
- )
161
- return (
162
- <div className={css.frame} role="group" aria-label={t('history.title')}>
163
- {action === undefined
164
- ? <div className={css.row} data-question-history={callId}>{content}</div>
165
- : <button
166
- type="button" className={css.row} data-question-history={callId} data-history-action={review ? 'review' : 'open'}
167
- onClick={() => { setFailedAction(action() ? null : actionKey) }}
168
- aria-label={`${actionLabel}${status === undefined ? '' : ` · ${status}`} · ${summary}`}
169
- >{content}</button>}
170
- {failedAction === actionKey && <span className={css.error} role="alert">{t('history.unavailable')}</span>}
171
- </div>
172
- )
173
- }