Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/tui/src/context/data.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type {
AgentV2Info,
CommandV2Info,
FormFormInfo,
FormUrlInfo,
IntegrationInfo,
LocationRef,
McpServer,
Expand Down Expand Up @@ -29,6 +31,8 @@ export type DataSessionStatus = "idle" | "running"

const messageIDFromEvent = (eventID: string) => eventID.replace(/^evt_/, "msg_")

export type FormInfo = FormFormInfo | FormUrlInfo

type LocationData = {
agent?: AgentV2Info[]
command?: CommandV2Info[]
Expand All @@ -54,6 +58,8 @@ type Data = {
message: Record<string, SessionMessage[]>
permission: Record<string, PermissionV2Request[]>
question: Record<string, QuestionV2Request[]>
// Pending forms keyed by session ID.
form: Record<string, FormInfo[]>
}
project: {
permission: Record<string, PermissionSavedInfo[]>
Expand Down Expand Up @@ -88,6 +94,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
message: {},
permission: {},
question: {},
form: {},
},
project: {
permission: {},
Expand Down Expand Up @@ -602,6 +609,22 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
),
)
break
case "form.created":
if (store.session.form[event.data.form.sessionID]?.some((form) => form.id === event.data.form.id)) break
setStore("session", "form", event.data.form.sessionID, [
...(store.session.form[event.data.form.sessionID] ?? []),
mutable(event.data.form),
])
break
case "form.replied":
case "form.cancelled":
setStore(
"session",
"form",
event.data.sessionID,
(store.session.form[event.data.sessionID] ?? []).filter((form) => form.id !== event.data.id),
)
break
case "shell.created":
setStore("location", locationKey(event.location ?? defaultLocation()), (data) => ({
...data,
Expand Down Expand Up @@ -728,6 +751,14 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
setStore("session", "question", sessionID, mutable(await sdk.api.question.list({ sessionID })))
},
},
form: {
list(sessionID: string) {
return store.session.form[sessionID]
},
async refresh(sessionID: string) {
setStore("session", "form", sessionID, mutable(await sdk.api.form.list({ sessionID })))
},
},
},
project: {
permission: {
Expand Down
15 changes: 15 additions & 0 deletions packages/tui/src/feature-plugins/system/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,24 @@ function sessionErrorMessage(error: SessionError) {
const tui: TuiPlugin = async (api) => {
const active = new Set<string>()
const errored = new Set<string>()
const forms = new Set<string>()
const questions = new Set<string>()
const permissions = new Set<string>()

api.event.on("form.created", (event) => {
if (forms.has(event.data.form.id)) return
forms.add(event.data.form.id)
notify(api, event.data.form.sessionID, "Input needs response", "question")
})

api.event.on("form.replied", (event) => {
forms.delete(event.data.id)
})

api.event.on("form.cancelled", (event) => {
forms.delete(event.data.id)
})

api.event.on("question.asked", (event) => {
if (questions.has(event.data.id)) return
questions.add(event.data.id)
Expand Down
Loading
Loading