@agent-api/app-engine 0.0.3 → 0.0.5
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.
|
@@ -204,6 +204,7 @@ export function createWorkbenchCommandController(options) {
|
|
|
204
204
|
return;
|
|
205
205
|
}
|
|
206
206
|
dispatch({ type: "settings.set", settings: { runPreset: normalized } });
|
|
207
|
+
dispatch({ type: "message.add", role: "system", text: `Preset set to ${normalized || "none"}.` });
|
|
207
208
|
dispatch({ type: "activity.add", text: `Preset: ${normalized || "none"}` });
|
|
208
209
|
}
|
|
209
210
|
async function validatePresetName(preset) {
|
|
@@ -6,10 +6,12 @@ export interface WorkbenchInputKey {
|
|
|
6
6
|
end?: boolean;
|
|
7
7
|
escape?: boolean;
|
|
8
8
|
home?: boolean;
|
|
9
|
+
leftArrow?: boolean;
|
|
9
10
|
meta?: boolean;
|
|
10
11
|
pageDown?: boolean;
|
|
11
12
|
pageUp?: boolean;
|
|
12
13
|
return?: boolean;
|
|
14
|
+
rightArrow?: boolean;
|
|
13
15
|
upArrow?: boolean;
|
|
14
16
|
}
|
|
15
17
|
export type WorkbenchInputEffect = {
|
|
@@ -30,11 +32,13 @@ export type WorkbenchInputEffect = {
|
|
|
30
32
|
type: "ignored_busy";
|
|
31
33
|
};
|
|
32
34
|
export interface WorkbenchInputResult {
|
|
35
|
+
cursor: number;
|
|
33
36
|
draft: string;
|
|
34
37
|
effects: WorkbenchInputEffect[];
|
|
35
38
|
}
|
|
36
39
|
export interface WorkbenchInputContext {
|
|
37
40
|
busy: boolean;
|
|
41
|
+
cursor?: number;
|
|
38
42
|
draft: string;
|
|
39
43
|
viewportHeight: number;
|
|
40
44
|
}
|
|
@@ -3,69 +3,102 @@ export function createWorkbenchInputController() {
|
|
|
3
3
|
const history = createInputHistory();
|
|
4
4
|
return {
|
|
5
5
|
handle(input, key, context) {
|
|
6
|
+
const cursor = clampCursor(context.cursor ?? context.draft.length, context.draft);
|
|
6
7
|
if (key.ctrl && input === "c")
|
|
7
|
-
return result(context.draft, { type: "exit" });
|
|
8
|
+
return result(context.draft, cursor, { type: "exit" });
|
|
8
9
|
if (key.pageUp || (key.ctrl && input === "u")) {
|
|
9
|
-
return result(context.draft, { type: "scroll", delta: Math.max(1, Math.floor(context.viewportHeight / 2)) });
|
|
10
|
+
return result(context.draft, cursor, { type: "scroll", delta: Math.max(1, Math.floor(context.viewportHeight / 2)) });
|
|
10
11
|
}
|
|
11
12
|
if (key.pageDown || (key.ctrl && input === "d")) {
|
|
12
|
-
return result(context.draft, { type: "scroll", delta: -Math.max(1, Math.floor(context.viewportHeight / 2)) });
|
|
13
|
+
return result(context.draft, cursor, { type: "scroll", delta: -Math.max(1, Math.floor(context.viewportHeight / 2)) });
|
|
13
14
|
}
|
|
14
|
-
if (key.home)
|
|
15
|
-
return result(context.draft,
|
|
16
|
-
if (key.end)
|
|
17
|
-
return result(context.draft,
|
|
15
|
+
if (key.home || (key.ctrl && input === "a"))
|
|
16
|
+
return result(context.draft, 0);
|
|
17
|
+
if (key.end || (key.ctrl && input === "e"))
|
|
18
|
+
return result(context.draft, context.draft.length);
|
|
19
|
+
if (key.leftArrow)
|
|
20
|
+
return result(context.draft, Math.max(0, cursor - 1));
|
|
21
|
+
if (key.rightArrow)
|
|
22
|
+
return result(context.draft, Math.min(context.draft.length, cursor + 1));
|
|
18
23
|
if (key.upArrow)
|
|
19
|
-
return
|
|
24
|
+
return historyResult(history.previous(context.draft));
|
|
20
25
|
if (key.downArrow)
|
|
21
|
-
return
|
|
26
|
+
return historyResult(history.next(context.draft));
|
|
22
27
|
if (context.busy) {
|
|
23
|
-
return handleBusyInput(input, key, context.draft, history);
|
|
28
|
+
return handleBusyInput(input, key, context.draft, cursor, history);
|
|
24
29
|
}
|
|
25
|
-
return handleReadyInput(input, key, context.draft, history);
|
|
30
|
+
return handleReadyInput(input, key, context.draft, cursor, history);
|
|
26
31
|
},
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
|
-
function handleBusyInput(input, key, draft, history) {
|
|
34
|
+
function handleBusyInput(input, key, draft, cursor, history) {
|
|
30
35
|
if (key.escape)
|
|
31
|
-
return result(draft, { type: "abort" });
|
|
36
|
+
return result(draft, cursor, { type: "abort" });
|
|
32
37
|
if (key.return) {
|
|
33
38
|
const command = draft.trim();
|
|
34
39
|
history.record(command);
|
|
35
40
|
if (command === "/abort" || command === "/cancel")
|
|
36
|
-
return result("", { type: "abort" });
|
|
41
|
+
return result("", 0, { type: "abort" });
|
|
37
42
|
if (command)
|
|
38
|
-
return result("", { type: "ignored_busy" });
|
|
39
|
-
return result("");
|
|
43
|
+
return result("", 0, { type: "ignored_busy" });
|
|
44
|
+
return result("", 0);
|
|
40
45
|
}
|
|
41
|
-
if (key.backspace
|
|
46
|
+
if (key.backspace) {
|
|
42
47
|
history.reset();
|
|
43
|
-
return
|
|
48
|
+
return deleteBeforeCursor(draft, cursor);
|
|
49
|
+
}
|
|
50
|
+
if (key.delete) {
|
|
51
|
+
history.reset();
|
|
52
|
+
return deleteAtCursor(draft, cursor);
|
|
44
53
|
}
|
|
45
54
|
if (input && !key.ctrl && !key.meta) {
|
|
46
55
|
history.reset();
|
|
47
|
-
return
|
|
56
|
+
return insertAtCursor(draft, cursor, input);
|
|
48
57
|
}
|
|
49
|
-
return result(draft);
|
|
58
|
+
return result(draft, cursor);
|
|
50
59
|
}
|
|
51
|
-
function handleReadyInput(input, key, draft, history) {
|
|
60
|
+
function handleReadyInput(input, key, draft, cursor, history) {
|
|
52
61
|
if (key.return) {
|
|
53
62
|
const prompt = draft.trim();
|
|
54
63
|
if (!prompt)
|
|
55
|
-
return result(draft);
|
|
64
|
+
return result(draft, cursor);
|
|
56
65
|
history.record(prompt);
|
|
57
|
-
return result("", { type: "submit", input: prompt });
|
|
66
|
+
return result("", 0, { type: "submit", input: prompt });
|
|
58
67
|
}
|
|
59
|
-
if (key.backspace
|
|
68
|
+
if (key.backspace) {
|
|
60
69
|
history.reset();
|
|
61
|
-
return
|
|
70
|
+
return deleteBeforeCursor(draft, cursor);
|
|
71
|
+
}
|
|
72
|
+
if (key.delete) {
|
|
73
|
+
history.reset();
|
|
74
|
+
return deleteAtCursor(draft, cursor);
|
|
62
75
|
}
|
|
63
76
|
if (input && !key.ctrl && !key.meta) {
|
|
64
77
|
history.reset();
|
|
65
|
-
return
|
|
78
|
+
return insertAtCursor(draft, cursor, input);
|
|
66
79
|
}
|
|
67
|
-
return result(draft);
|
|
80
|
+
return result(draft, cursor);
|
|
81
|
+
}
|
|
82
|
+
function result(draft, cursor, ...effects) {
|
|
83
|
+
return { cursor: clampCursor(cursor, draft), draft, effects };
|
|
84
|
+
}
|
|
85
|
+
function historyResult(draft) {
|
|
86
|
+
return result(draft, draft.length);
|
|
87
|
+
}
|
|
88
|
+
function insertAtCursor(draft, cursor, input) {
|
|
89
|
+
const next = `${draft.slice(0, cursor)}${input}${draft.slice(cursor)}`;
|
|
90
|
+
return result(next, cursor + input.length);
|
|
91
|
+
}
|
|
92
|
+
function deleteBeforeCursor(draft, cursor) {
|
|
93
|
+
if (cursor <= 0)
|
|
94
|
+
return result(draft, 0);
|
|
95
|
+
return result(`${draft.slice(0, cursor - 1)}${draft.slice(cursor)}`, cursor - 1);
|
|
96
|
+
}
|
|
97
|
+
function deleteAtCursor(draft, cursor) {
|
|
98
|
+
if (cursor >= draft.length)
|
|
99
|
+
return result(draft, cursor);
|
|
100
|
+
return result(`${draft.slice(0, cursor)}${draft.slice(cursor + 1)}`, cursor);
|
|
68
101
|
}
|
|
69
|
-
function
|
|
70
|
-
return
|
|
102
|
+
function clampCursor(cursor, draft) {
|
|
103
|
+
return Math.max(0, Math.min(draft.length, cursor));
|
|
71
104
|
}
|
|
@@ -22,7 +22,11 @@ export interface WorkbenchRenderModel {
|
|
|
22
22
|
workdir: string;
|
|
23
23
|
};
|
|
24
24
|
input: {
|
|
25
|
+
afterCursor: string;
|
|
26
|
+
beforeCursor: string;
|
|
25
27
|
busy: boolean;
|
|
28
|
+
cursor: number;
|
|
29
|
+
cursorText: string;
|
|
26
30
|
draft: string;
|
|
27
31
|
fullAccess: boolean;
|
|
28
32
|
label: string;
|
|
@@ -36,6 +40,7 @@ export interface WorkbenchRenderModel {
|
|
|
36
40
|
visibleActivities: WorkbenchState["activities"];
|
|
37
41
|
}
|
|
38
42
|
export interface BuildWorkbenchRenderModelInput {
|
|
43
|
+
cursor?: number;
|
|
39
44
|
draft: string;
|
|
40
45
|
profileName: string;
|
|
41
46
|
spinnerFrame: number;
|
|
@@ -15,6 +15,10 @@ export function buildWorkbenchRenderModel(input) {
|
|
|
15
15
|
viewportHeight,
|
|
16
16
|
width: transcriptWidth,
|
|
17
17
|
});
|
|
18
|
+
const cursor = Math.max(0, Math.min(input.draft.length, input.cursor ?? input.draft.length));
|
|
19
|
+
const beforeCursor = input.draft.slice(0, cursor);
|
|
20
|
+
const cursorText = input.draft[cursor] ?? " ";
|
|
21
|
+
const afterCursor = input.draft.slice(cursor + (cursor < input.draft.length ? 1 : 0));
|
|
18
22
|
return {
|
|
19
23
|
activityHeight,
|
|
20
24
|
footerText: [
|
|
@@ -39,7 +43,11 @@ export function buildWorkbenchRenderModel(input) {
|
|
|
39
43
|
workdir: input.state.workdir?.root || input.workdirFallback,
|
|
40
44
|
},
|
|
41
45
|
input: {
|
|
46
|
+
afterCursor,
|
|
47
|
+
beforeCursor,
|
|
42
48
|
busy: input.state.busy,
|
|
49
|
+
cursor,
|
|
50
|
+
cursorText,
|
|
43
51
|
draft: input.draft,
|
|
44
52
|
fullAccess: input.state.accessMode === "full",
|
|
45
53
|
label: input.state.busy ? "working" : "you",
|
package/package.json
CHANGED