Skip to content

Commit 82a3270

Browse files
chore: generate
1 parent c0a258b commit 82a3270

5 files changed

Lines changed: 60 additions & 69 deletions

File tree

packages/app/src/components/prompt-input/history-store.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { createStore, type SetStoreFunction, type Store } from "solid-js/store"
22
import type { Prompt } from "@/context/prompt"
33
import { Persist, persisted } from "@/utils/persist"
4-
import {
5-
prependHistoryEntry,
6-
type PromptHistoryComment,
7-
type PromptHistoryStoredEntry,
8-
} from "./history"
4+
import { prependHistoryEntry, type PromptHistoryComment, type PromptHistoryStoredEntry } from "./history"
95

106
export type PromptInputHistory = {
117
entries: (mode: "normal" | "shell") => PromptHistoryStoredEntry[]

packages/session-ui/src/v2/components/prompt-input/attachments.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ export type PromptInputV2AttachmentConfig = {
7979
getPathForFile?: (file: File) => string
8080
}
8181

82-
export function createPromptInputV2Attachments(input: PromptInputV2AttachmentConfig & {
83-
capture: () => PromptTarget
84-
editor: () => HTMLElement | undefined
85-
focusEditor: () => void
86-
addPart: (part: PromptInputV2Prompt[number]) => boolean
87-
setDraggingType: (type: "image" | "@mention" | null) => void
88-
}) {
82+
export function createPromptInputV2Attachments(
83+
input: PromptInputV2AttachmentConfig & {
84+
capture: () => PromptTarget
85+
editor: () => HTMLElement | undefined
86+
focusEditor: () => void
87+
addPart: (part: PromptInputV2Prompt[number]) => boolean
88+
setDraggingType: (type: "image" | "@mention" | null) => void
89+
},
90+
) {
8991
const capture = () => {
9092
const prompt = input.capture()
9193
const editor = input.editor()
@@ -113,13 +115,10 @@ export function createPromptInputV2Attachments(input: PromptInputV2AttachmentCon
113115
return true
114116
}
115117
const addAttachments = async (files: File[], toast = true, target = capture()) => {
116-
const found = await files.reduce(
117-
async (result, file) => {
118-
const previous = await result
119-
return (await add(file, false, target)) || previous
120-
},
121-
Promise.resolve(false),
122-
)
118+
const found = await files.reduce(async (result, file) => {
119+
const previous = await result
120+
return (await add(file, false, target)) || previous
121+
}, Promise.resolve(false))
123122
if (!found && files.length > 0 && toast) input.warn()
124123
return found
125124
}

packages/session-ui/src/v2/components/prompt-input/machine.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ describe("prompt input v2 interaction machine", () => {
9393
{ type: "commands.open" },
9494
persisted("existing text"),
9595
)
96-
const selected = transitionPromptInputV2(open.state, { type: "popover.select", item: command }, persisted("existing text"))
96+
const selected = transitionPromptInputV2(
97+
open.state,
98+
{ type: "popover.select", item: command },
99+
persisted("existing text"),
100+
)
97101

98102
expect(selected.commands).toContainEqual({ type: "draft.setText", value: "/review existing text" })
99103
expect(selected.state.popover).toEqual({ type: "closed" })

packages/session-ui/src/v2/components/prompt-input/machine.ts

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,19 @@ function inputChanged(state: PromptInputV2InteractionState, value: string, persi
9191
const context = value.match(/(?:^|\s)@([^\s@]*)$/)
9292
if (context) {
9393
const query = context[1] ?? ""
94-
return changed(
95-
{ ...state, popover: { type: "context", query }, focus: "editor" },
96-
[
97-
...setText,
98-
{ type: "popover.filter", popover: "context", query },
99-
],
100-
)
94+
return changed({ ...state, popover: { type: "context", query }, focus: "editor" }, [
95+
...setText,
96+
{ type: "popover.filter", popover: "context", query },
97+
])
10198
}
10299

103100
const command = value.match(/^\/([^\s/]*)$/)
104101
if (command) {
105102
const query = command[1] ?? ""
106-
return changed(
107-
{ ...state, popover: { type: "command-inline", query }, focus: "editor" },
108-
[
109-
...setText,
110-
{ type: "popover.filter", popover: "command", query },
111-
],
112-
)
103+
return changed({ ...state, popover: { type: "command-inline", query }, focus: "editor" }, [
104+
...setText,
105+
{ type: "popover.filter", popover: "command", query },
106+
])
113107
}
114108

115109
return changed(
@@ -123,45 +117,35 @@ function openCommands(
123117
persisted: PromptInputV2PersistedState,
124118
): PromptInputV2Transition {
125119
if (!populated(persisted)) {
126-
return changed(
127-
{ ...state, popover: { type: "command-inline", query: "" }, focus: "editor" },
128-
[
129-
{ type: "draft.setText", value: promptText(persisted) + "/" },
130-
{ type: "popover.filter", popover: "command", query: "" },
131-
{ type: "focus.editor" },
132-
],
133-
)
134-
}
135-
return changed(
136-
{ ...state, popover: { type: "command-menu", query: "" }, focus: "command-search" },
137-
[
120+
return changed({ ...state, popover: { type: "command-inline", query: "" }, focus: "editor" }, [
121+
{ type: "draft.setText", value: promptText(persisted) + "/" },
138122
{ type: "popover.filter", popover: "command", query: "" },
139-
{ type: "focus.command-search" },
140-
],
141-
)
123+
{ type: "focus.editor" },
124+
])
125+
}
126+
return changed({ ...state, popover: { type: "command-menu", query: "" }, focus: "command-search" }, [
127+
{ type: "popover.filter", popover: "command", query: "" },
128+
{ type: "focus.command-search" },
129+
])
142130
}
143131

144132
function openContext(
145133
state: PromptInputV2InteractionState,
146134
persisted: PromptInputV2PersistedState,
147135
): PromptInputV2Transition {
148-
return changed(
149-
{ ...state, popover: { type: "context", query: "" }, focus: "editor" },
150-
[
151-
{ type: "draft.setText", value: promptText(persisted) + "@" },
152-
{ type: "popover.filter", popover: "context", query: "" },
153-
{ type: "focus.editor" },
154-
],
155-
)
136+
return changed({ ...state, popover: { type: "context", query: "" }, focus: "editor" }, [
137+
{ type: "draft.setText", value: promptText(persisted) + "@" },
138+
{ type: "popover.filter", popover: "context", query: "" },
139+
{ type: "focus.editor" },
140+
])
156141
}
157142

158143
function queryChanged(state: PromptInputV2InteractionState, query: string): PromptInputV2Transition {
159144
if (state.popover.type === "closed") return unchanged(state)
160145
const popover = state.popover.type === "context" ? "context" : "command"
161-
return changed(
162-
{ ...state, popover: { ...state.popover, query, activeID: undefined } },
163-
[{ type: "popover.filter", popover, query }],
164-
)
146+
return changed({ ...state, popover: { ...state.popover, query, activeID: undefined } }, [
147+
{ type: "popover.filter", popover, query },
148+
])
165149
}
166150

167151
function resultsChanged(state: PromptInputV2InteractionState, ids: string[]): PromptInputV2Transition {
@@ -215,20 +199,26 @@ function keyDown(
215199
return unchanged(state)
216200
}
217201
if (event.key === "Escape") {
218-
return changed(
219-
{ ...state, popover: { type: "closed" }, focus: "editor" },
220-
[{ type: "focus.editor" }],
221-
true,
222-
)
202+
return changed({ ...state, popover: { type: "closed" }, focus: "editor" }, [{ type: "focus.editor" }], true)
223203
}
224204
if (event.key === "Tab" || (event.key === "Enter" && !event.composing)) {
225205
if (!state.popover.activeID) return unchanged(state, true)
226206
return unchanged(state, true, [{ type: "suggestion.select", id: state.popover.activeID }])
227207
}
228-
const direction = event.key === "ArrowDown" || (event.ctrl && event.key === "n") ? 1 : event.key === "ArrowUp" || (event.ctrl && event.key === "p") ? -1 : 0
208+
const direction =
209+
event.key === "ArrowDown" || (event.ctrl && event.key === "n")
210+
? 1
211+
: event.key === "ArrowUp" || (event.ctrl && event.key === "p")
212+
? -1
213+
: 0
229214
if (!direction || event.ids.length === 0) return unchanged(state)
230215
const current = state.popover.activeID ? event.ids.indexOf(state.popover.activeID) : -1
231-
const index = current < 0 ? (direction === 1 ? 0 : event.ids.length - 1) : (current + direction + event.ids.length) % event.ids.length
216+
const index =
217+
current < 0
218+
? direction === 1
219+
? 0
220+
: event.ids.length - 1
221+
: (current + direction + event.ids.length) % event.ids.length
232222
return changed({ ...state, popover: { ...state.popover, activeID: event.ids[index] } }, [], true)
233223
}
234224

packages/session-ui/src/v2/components/prompt-input/store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export function createPromptInputV2Store(input: PromptInputV2StoreInput) {
6767
setStore()("context", "items", (items) => items.filter((item) => item.key !== key))
6868
},
6969
addMention(mention: PromptInputV2FilePart | PromptInputV2AgentPart) {
70-
const text = store().prompt.map((part) => ("content" in part ? part.content : "")).join("")
70+
const text = store()
71+
.prompt.map((part) => ("content" in part ? part.content : ""))
72+
.join("")
7173
const end = store().cursor ?? text.length
7274
const start = text.slice(0, end).lastIndexOf("@")
7375
setStore()("prompt", insertMention(store().prompt, start < 0 ? end : start, end, mention))

0 commit comments

Comments
 (0)