Skip to content

Commit 2508a74

Browse files
committed
refactor(tui): make data sync owner-driven
1 parent 947566f commit 2508a74

10 files changed

Lines changed: 519 additions & 407 deletions

File tree

‎packages/plugin/src/v2/tui/context.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import type { JSX } from "@opentui/solid"
2424

2525
interface LocationCollection<Value> {
2626
list(location?: LocationRef): Value[] | undefined
27-
refresh(location?: LocationRef): Promise<void>
27+
sync(location?: LocationRef): Promise<void>
28+
invalidate(location?: LocationRef): void
2829
}
2930

3031
export interface Data {
@@ -42,37 +43,45 @@ export interface Data {
4243
status(sessionID: string): "idle" | "running"
4344
readonly pending: {
4445
list(sessionID: string): SessionPendingInfo[]
45-
refresh(sessionID: string): Promise<void>
46+
sync(sessionID: string): Promise<void>
47+
invalidate(sessionID: string): void
4648
}
47-
refresh(sessionID: string): Promise<void>
49+
sync(sessionID: string): Promise<void>
50+
invalidate(sessionID: string): void
4851
readonly message: {
4952
list(sessionID: string): SessionMessageInfo[]
5053
get(sessionID: string, messageID: string): SessionMessageInfo | undefined
51-
refresh(sessionID: string): Promise<void>
54+
sync(sessionID: string): Promise<void>
55+
invalidate(sessionID: string): void
5256
}
5357
readonly permission: {
5458
list(sessionID: string): PermissionV2Request[] | undefined
55-
refresh(sessionID: string): Promise<void>
59+
sync(sessionID: string): Promise<void>
60+
invalidate(sessionID: string): void
5661
}
5762
readonly form: {
5863
list(sessionID: string, location?: LocationRef): Array<FormInfo & { readonly location?: LocationRef }> | undefined
59-
refresh(sessionID: string, location?: LocationRef): Promise<void>
64+
sync(sessionID: string, location?: LocationRef): Promise<void>
65+
invalidate(sessionID: string, location?: LocationRef): void
6066
}
6167
}
6268
readonly project: {
6369
readonly permission: {
6470
list(projectID: string): PermissionSavedInfo[] | undefined
65-
refresh(projectID: string): Promise<void>
71+
sync(projectID: string): Promise<void>
72+
invalidate(projectID: string): void
6673
}
6774
}
6875
readonly shell: {
6976
list(location?: LocationRef): ShellInfo[]
7077
get(id: string): ShellInfo | undefined
71-
refresh(location?: LocationRef): Promise<void>
78+
sync(location?: LocationRef): Promise<void>
79+
invalidate(location?: LocationRef): void
7280
}
7381
readonly location: {
7482
default(): LocationRef
75-
refresh(location?: LocationRef): Promise<void>
83+
sync(location?: LocationRef): Promise<void>
84+
invalidate(location?: LocationRef): void
7685
readonly agent: LocationCollection<AgentInfo>
7786
readonly command: LocationCollection<CommandInfo>
7887
readonly integration: LocationCollection<IntegrationInfo>

‎packages/tui/src/component/dialog-integration.tsx‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,10 @@ async function connected(
467467
toast: ReturnType<typeof useToast>,
468468
onConnected?: OnIntegrationConnected,
469469
) {
470-
await Promise.all([
471-
data.location.integration.refresh(),
472-
data.location.model.refresh(),
473-
data.location.provider.refresh(),
474-
])
470+
data.location.integration.invalidate()
471+
data.location.model.invalidate()
472+
data.location.provider.invalidate()
473+
await Promise.all([data.location.integration.sync(), data.location.model.sync(), data.location.provider.sync()])
475474
toast.show({ variant: "success", message: `Connected ${integration.name}` })
476475
if (onConnected) {
477476
onConnected(providerID(data, integration.id))
@@ -498,11 +497,10 @@ async function disconnected(
498497
dialog: ReturnType<typeof useDialog>,
499498
toast: ReturnType<typeof useToast>,
500499
) {
501-
await Promise.all([
502-
data.location.integration.refresh(),
503-
data.location.model.refresh(),
504-
data.location.provider.refresh(),
505-
])
500+
data.location.integration.invalidate()
501+
data.location.model.invalidate()
502+
data.location.provider.invalidate()
503+
await Promise.all([data.location.integration.sync(), data.location.model.sync(), data.location.provider.sync()])
506504
toast.show({ variant: "success", message: `Disconnected ${name}` })
507505
dialog.clear()
508506
}

‎packages/tui/src/component/dialog-skill.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function DialogSkill(props: DialogSkillProps) {
2525
.then(async () => {
2626
const current = data.location.skill.list(props.location)
2727
if (current) return current
28-
await data.location.skill.refresh(props.location)
28+
await data.location.skill.sync(props.location)
2929
return data.location.skill.list(props.location) ?? []
3030
})
3131
// Catch so the rejected resource never reaches the memo below: reading

‎packages/tui/src/component/prompt/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ export function Prompt(props: PromptProps) {
10551055
} else {
10561056
move.startSubmit()
10571057
if (!session) {
1058-
await data.session.refresh(sessionID)
1058+
await data.session.sync(sessionID)
10591059
session = data.session.get(sessionID)
10601060
}
10611061
if (session?.agent !== agent.id) {

‎packages/tui/src/component/prompt/move.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
4242
const directory = result.directory
4343
if (!directory) throw new Error("No project copy directory returned")
4444

45-
// Call a location-based route to make sure it's bootstrapped before moving on.
45+
// Call a location-based route to initialize it before moving on.
4646
await client.api.location.get({ location: { directory } })
4747

4848
setProgress("Creating session")
@@ -139,7 +139,7 @@ export function usePromptMove(input: { projectID: () => string | undefined; sess
139139
async function resolveSession(sessionID: string) {
140140
const session = data.session.get(sessionID)
141141
if (session) return session
142-
await data.session.refresh(sessionID).catch(() => undefined)
142+
await data.session.sync(sessionID).catch(() => undefined)
143143
return data.session.get(sessionID)
144144
}
145145

0 commit comments

Comments
 (0)