wave-code 0.13.6 → 0.14.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/dist/components/ChatInterface.d.ts.map +1 -1
- package/dist/components/ChatInterface.js +1 -1
- package/dist/components/ConfirmationSelector.d.ts +0 -1
- package/dist/components/ConfirmationSelector.d.ts.map +1 -1
- package/dist/components/ConfirmationSelector.js +111 -259
- package/dist/components/MessageList.d.ts.map +1 -1
- package/dist/components/MessageList.js +4 -6
- package/dist/components/TaskNotificationMessage.js +1 -1
- package/dist/contexts/useChat.d.ts.map +1 -1
- package/dist/contexts/useChat.js +3 -4
- package/dist/managers/inputHandlers.d.ts.map +1 -1
- package/dist/managers/inputHandlers.js +6 -9
- package/dist/managers/inputReducer.d.ts +6 -0
- package/dist/managers/inputReducer.d.ts.map +1 -1
- package/dist/managers/inputReducer.js +15 -0
- package/dist/reducers/confirmationReducer.d.ts +26 -0
- package/dist/reducers/confirmationReducer.d.ts.map +1 -0
- package/dist/reducers/confirmationReducer.js +45 -0
- package/dist/reducers/questionReducer.d.ts +69 -0
- package/dist/reducers/questionReducer.d.ts.map +1 -0
- package/dist/reducers/questionReducer.js +195 -0
- package/package.json +2 -2
- package/src/components/ChatInterface.tsx +0 -1
- package/src/components/ConfirmationSelector.tsx +122 -304
- package/src/components/MessageList.tsx +10 -14
- package/src/components/TaskNotificationMessage.tsx +1 -1
- package/src/contexts/useChat.tsx +3 -4
- package/src/managers/inputHandlers.ts +6 -8
- package/src/managers/inputReducer.ts +19 -0
- package/src/reducers/confirmationReducer.ts +74 -0
- package/src/reducers/questionReducer.ts +251 -0
|
@@ -173,6 +173,10 @@ export type InputAction =
|
|
|
173
173
|
| { type: "CLEAR_INPUT" }
|
|
174
174
|
| { type: "START_PASTE"; payload: { buffer: string; cursorPosition: number } }
|
|
175
175
|
| { type: "APPEND_PASTE_BUFFER"; payload: string }
|
|
176
|
+
| {
|
|
177
|
+
type: "APPEND_PASTE_CHUNK";
|
|
178
|
+
payload: { chunk: string; cursorPosition: number };
|
|
179
|
+
}
|
|
176
180
|
| { type: "END_PASTE" }
|
|
177
181
|
| {
|
|
178
182
|
type: "ADD_IMAGE_AND_INSERT_PLACEHOLDER";
|
|
@@ -407,6 +411,21 @@ export function inputReducer(
|
|
|
407
411
|
cursorPosition: 0,
|
|
408
412
|
historyIndex: -1,
|
|
409
413
|
};
|
|
414
|
+
case "APPEND_PASTE_CHUNK": {
|
|
415
|
+
// The reducer determines if this is a new paste or a continuation
|
|
416
|
+
// by checking if pasteBuffer is already set. This avoids the
|
|
417
|
+
// handler needing to track isPasting state, which can be stale
|
|
418
|
+
// when multiple dispatches fire before React state updates.
|
|
419
|
+
const isNewPaste = !state.pasteBuffer;
|
|
420
|
+
return {
|
|
421
|
+
...state,
|
|
422
|
+
isPasting: true,
|
|
423
|
+
pasteBuffer: state.pasteBuffer + action.payload.chunk,
|
|
424
|
+
initialPasteCursorPosition: isNewPaste
|
|
425
|
+
? action.payload.cursorPosition
|
|
426
|
+
: state.initialPasteCursorPosition,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
410
429
|
case "START_PASTE":
|
|
411
430
|
return {
|
|
412
431
|
...state,
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { PermissionDecision } from "wave-agent-sdk";
|
|
2
|
+
|
|
3
|
+
export interface ConfirmationState {
|
|
4
|
+
selectedOption: "clear" | "auto" | "allow" | "alternative";
|
|
5
|
+
alternativeText: string;
|
|
6
|
+
alternativeCursorPosition: number;
|
|
7
|
+
hasUserInput: boolean;
|
|
8
|
+
decision: PermissionDecision | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ConfirmationAction =
|
|
12
|
+
| { type: "SELECT_OPTION"; option: ConfirmationState["selectedOption"] }
|
|
13
|
+
| { type: "INSERT_TEXT"; text: string }
|
|
14
|
+
| { type: "BACKSPACE" }
|
|
15
|
+
| { type: "MOVE_CURSOR_LEFT" }
|
|
16
|
+
| { type: "MOVE_CURSOR_RIGHT" }
|
|
17
|
+
| { type: "CONFIRM"; decision: PermissionDecision };
|
|
18
|
+
|
|
19
|
+
export function confirmationReducer(
|
|
20
|
+
state: ConfirmationState,
|
|
21
|
+
action: ConfirmationAction,
|
|
22
|
+
): ConfirmationState {
|
|
23
|
+
switch (action.type) {
|
|
24
|
+
case "SELECT_OPTION":
|
|
25
|
+
return { ...state, selectedOption: action.option };
|
|
26
|
+
case "INSERT_TEXT": {
|
|
27
|
+
const nextText =
|
|
28
|
+
state.alternativeText.slice(0, state.alternativeCursorPosition) +
|
|
29
|
+
action.text +
|
|
30
|
+
state.alternativeText.slice(state.alternativeCursorPosition);
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
selectedOption: "alternative",
|
|
34
|
+
alternativeText: nextText,
|
|
35
|
+
alternativeCursorPosition:
|
|
36
|
+
state.alternativeCursorPosition + action.text.length,
|
|
37
|
+
hasUserInput: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
case "BACKSPACE": {
|
|
41
|
+
if (state.alternativeCursorPosition <= 0) return state;
|
|
42
|
+
const nextText =
|
|
43
|
+
state.alternativeText.slice(0, state.alternativeCursorPosition - 1) +
|
|
44
|
+
state.alternativeText.slice(state.alternativeCursorPosition);
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
selectedOption: "alternative",
|
|
48
|
+
alternativeText: nextText,
|
|
49
|
+
alternativeCursorPosition: state.alternativeCursorPosition - 1,
|
|
50
|
+
hasUserInput: nextText.length > 0,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case "MOVE_CURSOR_LEFT":
|
|
54
|
+
return {
|
|
55
|
+
...state,
|
|
56
|
+
alternativeCursorPosition: Math.max(
|
|
57
|
+
0,
|
|
58
|
+
state.alternativeCursorPosition - 1,
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
case "MOVE_CURSOR_RIGHT":
|
|
62
|
+
return {
|
|
63
|
+
...state,
|
|
64
|
+
alternativeCursorPosition: Math.min(
|
|
65
|
+
state.alternativeText.length,
|
|
66
|
+
state.alternativeCursorPosition + 1,
|
|
67
|
+
),
|
|
68
|
+
};
|
|
69
|
+
case "CONFIRM":
|
|
70
|
+
return { ...state, decision: action.decision };
|
|
71
|
+
default:
|
|
72
|
+
return state;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import type { PermissionDecision } from "wave-agent-sdk";
|
|
2
|
+
|
|
3
|
+
export interface QuestionSavedState {
|
|
4
|
+
selectedOptionIndex: number;
|
|
5
|
+
selectedOptionIndices: Set<number>;
|
|
6
|
+
otherText: string;
|
|
7
|
+
otherCursorPosition: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface QuestionState {
|
|
11
|
+
currentQuestionIndex: number;
|
|
12
|
+
selectedOptionIndex: number;
|
|
13
|
+
selectedOptionIndices: Set<number>;
|
|
14
|
+
userAnswers: Record<string, string>;
|
|
15
|
+
otherText: string;
|
|
16
|
+
otherCursorPosition: number;
|
|
17
|
+
savedStates: Record<number, QuestionSavedState>;
|
|
18
|
+
decision: PermissionDecision | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type QuestionAction =
|
|
22
|
+
| { type: "SELECT_OPTION"; index: number }
|
|
23
|
+
| { type: "MOVE_OPTION_UP"; maxIndex: number }
|
|
24
|
+
| { type: "MOVE_OPTION_DOWN"; maxIndex: number }
|
|
25
|
+
| {
|
|
26
|
+
type: "TOGGLE_MULTI_SELECT";
|
|
27
|
+
optionsLength: number;
|
|
28
|
+
}
|
|
29
|
+
| { type: "CYCLE_QUESTION"; shift: boolean; questionCount: number }
|
|
30
|
+
| { type: "INSERT_OTHER"; text: string; optionsLength: number }
|
|
31
|
+
| { type: "DELETE_OTHER"; optionsLength: number }
|
|
32
|
+
| { type: "MOVE_OTHER_LEFT"; optionsLength: number }
|
|
33
|
+
| { type: "MOVE_OTHER_RIGHT"; optionsLength: number }
|
|
34
|
+
| {
|
|
35
|
+
type: "CONFIRM_ANSWER";
|
|
36
|
+
currentQuestion: {
|
|
37
|
+
question: string;
|
|
38
|
+
options: Array<{ label: string }>;
|
|
39
|
+
multiSelect?: boolean;
|
|
40
|
+
};
|
|
41
|
+
options: Array<{ label: string }>;
|
|
42
|
+
isMultiSelect: boolean;
|
|
43
|
+
questions: Array<{
|
|
44
|
+
question: string;
|
|
45
|
+
options: Array<{ label: string }>;
|
|
46
|
+
multiSelect?: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function buildAnswerFromSavedState(
|
|
51
|
+
q: {
|
|
52
|
+
question: string;
|
|
53
|
+
options: Array<{ label: string }>;
|
|
54
|
+
multiSelect?: boolean;
|
|
55
|
+
},
|
|
56
|
+
s: QuestionSavedState,
|
|
57
|
+
): string {
|
|
58
|
+
const opts = [...q.options, { label: "Other" }];
|
|
59
|
+
let a = "";
|
|
60
|
+
if (q.multiSelect) {
|
|
61
|
+
const selectedLabels = Array.from(s.selectedOptionIndices)
|
|
62
|
+
.filter((i) => i < q.options.length)
|
|
63
|
+
.map((i) => q.options[i].label);
|
|
64
|
+
const isOtherChecked = s.selectedOptionIndices.has(opts.length - 1);
|
|
65
|
+
if (isOtherChecked && s.otherText.trim()) {
|
|
66
|
+
selectedLabels.push(s.otherText.trim());
|
|
67
|
+
}
|
|
68
|
+
a = selectedLabels.join(", ");
|
|
69
|
+
} else {
|
|
70
|
+
if (s.selectedOptionIndex === opts.length - 1) {
|
|
71
|
+
a = s.otherText.trim();
|
|
72
|
+
} else {
|
|
73
|
+
a = opts[s.selectedOptionIndex].label;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return a;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function questionReducer(
|
|
80
|
+
state: QuestionState,
|
|
81
|
+
action: QuestionAction,
|
|
82
|
+
): QuestionState {
|
|
83
|
+
switch (action.type) {
|
|
84
|
+
case "SELECT_OPTION":
|
|
85
|
+
return { ...state, selectedOptionIndex: action.index };
|
|
86
|
+
case "MOVE_OPTION_UP":
|
|
87
|
+
return {
|
|
88
|
+
...state,
|
|
89
|
+
selectedOptionIndex: Math.max(0, state.selectedOptionIndex - 1),
|
|
90
|
+
};
|
|
91
|
+
case "MOVE_OPTION_DOWN":
|
|
92
|
+
return {
|
|
93
|
+
...state,
|
|
94
|
+
selectedOptionIndex: Math.min(
|
|
95
|
+
action.maxIndex,
|
|
96
|
+
state.selectedOptionIndex + 1,
|
|
97
|
+
),
|
|
98
|
+
};
|
|
99
|
+
case "TOGGLE_MULTI_SELECT": {
|
|
100
|
+
const nextIndices = new Set(state.selectedOptionIndices);
|
|
101
|
+
if (nextIndices.has(state.selectedOptionIndex))
|
|
102
|
+
nextIndices.delete(state.selectedOptionIndex);
|
|
103
|
+
else nextIndices.add(state.selectedOptionIndex);
|
|
104
|
+
return { ...state, selectedOptionIndices: nextIndices };
|
|
105
|
+
}
|
|
106
|
+
case "CYCLE_QUESTION": {
|
|
107
|
+
const direction = action.shift ? -1 : 1;
|
|
108
|
+
let nextIndex = state.currentQuestionIndex + direction;
|
|
109
|
+
if (nextIndex < 0) nextIndex = action.questionCount - 1;
|
|
110
|
+
if (nextIndex >= action.questionCount) nextIndex = 0;
|
|
111
|
+
if (nextIndex === state.currentQuestionIndex) return state;
|
|
112
|
+
const savedStates = {
|
|
113
|
+
...state.savedStates,
|
|
114
|
+
[state.currentQuestionIndex]: {
|
|
115
|
+
selectedOptionIndex: state.selectedOptionIndex,
|
|
116
|
+
selectedOptionIndices: state.selectedOptionIndices,
|
|
117
|
+
otherText: state.otherText,
|
|
118
|
+
otherCursorPosition: state.otherCursorPosition,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
const nextState = savedStates[nextIndex] || {
|
|
122
|
+
selectedOptionIndex: 0,
|
|
123
|
+
selectedOptionIndices: new Set<number>(),
|
|
124
|
+
otherText: "",
|
|
125
|
+
otherCursorPosition: 0,
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
...state,
|
|
129
|
+
currentQuestionIndex: nextIndex,
|
|
130
|
+
...nextState,
|
|
131
|
+
savedStates,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
case "INSERT_OTHER": {
|
|
135
|
+
if (state.selectedOptionIndex !== action.optionsLength - 1) return state;
|
|
136
|
+
const newText =
|
|
137
|
+
state.otherText.slice(0, state.otherCursorPosition) +
|
|
138
|
+
action.text +
|
|
139
|
+
state.otherText.slice(state.otherCursorPosition);
|
|
140
|
+
return {
|
|
141
|
+
...state,
|
|
142
|
+
otherText: newText,
|
|
143
|
+
otherCursorPosition: state.otherCursorPosition + action.text.length,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
case "DELETE_OTHER":
|
|
147
|
+
if (state.selectedOptionIndex !== action.optionsLength - 1) return state;
|
|
148
|
+
if (state.otherCursorPosition > 0) {
|
|
149
|
+
return {
|
|
150
|
+
...state,
|
|
151
|
+
otherText:
|
|
152
|
+
state.otherText.slice(0, state.otherCursorPosition - 1) +
|
|
153
|
+
state.otherText.slice(state.otherCursorPosition),
|
|
154
|
+
otherCursorPosition: state.otherCursorPosition - 1,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return state;
|
|
158
|
+
case "MOVE_OTHER_LEFT":
|
|
159
|
+
if (state.selectedOptionIndex !== action.optionsLength - 1) return state;
|
|
160
|
+
return {
|
|
161
|
+
...state,
|
|
162
|
+
otherCursorPosition: Math.max(0, state.otherCursorPosition - 1),
|
|
163
|
+
};
|
|
164
|
+
case "MOVE_OTHER_RIGHT":
|
|
165
|
+
if (state.selectedOptionIndex !== action.optionsLength - 1) return state;
|
|
166
|
+
return {
|
|
167
|
+
...state,
|
|
168
|
+
otherCursorPosition: Math.min(
|
|
169
|
+
state.otherText.length,
|
|
170
|
+
state.otherCursorPosition + 1,
|
|
171
|
+
),
|
|
172
|
+
};
|
|
173
|
+
case "CONFIRM_ANSWER": {
|
|
174
|
+
const { currentQuestion: cq, options, isMultiSelect, questions } = action;
|
|
175
|
+
const isOtherFocused = state.selectedOptionIndex === options.length - 1;
|
|
176
|
+
let answer = "";
|
|
177
|
+
if (isMultiSelect) {
|
|
178
|
+
const selectedLabels = Array.from(state.selectedOptionIndices)
|
|
179
|
+
.filter((i) => i < cq.options.length)
|
|
180
|
+
.map((i) => cq.options[i].label);
|
|
181
|
+
const isOtherChecked = state.selectedOptionIndices.has(
|
|
182
|
+
options.length - 1,
|
|
183
|
+
);
|
|
184
|
+
if (isOtherChecked && state.otherText.trim()) {
|
|
185
|
+
selectedLabels.push(state.otherText.trim());
|
|
186
|
+
}
|
|
187
|
+
answer = selectedLabels.join(", ");
|
|
188
|
+
} else {
|
|
189
|
+
if (isOtherFocused) {
|
|
190
|
+
answer = state.otherText.trim();
|
|
191
|
+
} else {
|
|
192
|
+
answer = options[state.selectedOptionIndex].label;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!answer) return state;
|
|
196
|
+
|
|
197
|
+
const newAnswers = {
|
|
198
|
+
...state.userAnswers,
|
|
199
|
+
[cq.question]: answer,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
if (state.currentQuestionIndex < questions.length - 1) {
|
|
203
|
+
const nextIndex = state.currentQuestionIndex + 1;
|
|
204
|
+
const savedStates = {
|
|
205
|
+
...state.savedStates,
|
|
206
|
+
[state.currentQuestionIndex]: {
|
|
207
|
+
selectedOptionIndex: state.selectedOptionIndex,
|
|
208
|
+
selectedOptionIndices: state.selectedOptionIndices,
|
|
209
|
+
otherText: state.otherText,
|
|
210
|
+
otherCursorPosition: state.otherCursorPosition,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
const nextState = savedStates[nextIndex] || {
|
|
214
|
+
selectedOptionIndex: 0,
|
|
215
|
+
selectedOptionIndices: new Set<number>(),
|
|
216
|
+
otherText: "",
|
|
217
|
+
otherCursorPosition: 0,
|
|
218
|
+
};
|
|
219
|
+
return {
|
|
220
|
+
...state,
|
|
221
|
+
currentQuestionIndex: nextIndex,
|
|
222
|
+
...nextState,
|
|
223
|
+
userAnswers: newAnswers,
|
|
224
|
+
savedStates,
|
|
225
|
+
};
|
|
226
|
+
} else {
|
|
227
|
+
const finalAnswers = { ...newAnswers };
|
|
228
|
+
for (const [idxStr, s] of Object.entries(state.savedStates)) {
|
|
229
|
+
const idx = parseInt(idxStr);
|
|
230
|
+
const q = questions[idx];
|
|
231
|
+
if (q && !finalAnswers[q.question]) {
|
|
232
|
+
const a = buildAnswerFromSavedState(q, s);
|
|
233
|
+
if (a) finalAnswers[q.question] = a;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const allAnswered = questions.every((q) => finalAnswers[q.question]);
|
|
237
|
+
if (!allAnswered) return state;
|
|
238
|
+
return {
|
|
239
|
+
...state,
|
|
240
|
+
userAnswers: finalAnswers,
|
|
241
|
+
decision: {
|
|
242
|
+
behavior: "allow",
|
|
243
|
+
message: JSON.stringify(finalAnswers),
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
default:
|
|
249
|
+
return state;
|
|
250
|
+
}
|
|
251
|
+
}
|