|
|
@@ -16,6 +16,7 @@ import { createStore, produce, reconcile } from "solid-js/store"
|
|
|
import { useSDK } from "@tui/context/sdk"
|
|
|
import { Binary } from "@/util/binary"
|
|
|
import { createSimpleContext } from "./helper"
|
|
|
+import type { Snapshot } from "@/snapshot"
|
|
|
|
|
|
export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|
|
name: "Sync",
|
|
|
@@ -30,6 +31,9 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|
|
}
|
|
|
config: Config
|
|
|
session: Session[]
|
|
|
+ session_diff: {
|
|
|
+ [sessionID: string]: Snapshot.FileDiff[]
|
|
|
+ }
|
|
|
todo: {
|
|
|
[sessionID: string]: Todo[]
|
|
|
}
|
|
|
@@ -52,6 +56,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|
|
command: [],
|
|
|
provider: [],
|
|
|
session: [],
|
|
|
+ session_diff: {},
|
|
|
todo: {},
|
|
|
message: {},
|
|
|
part: {},
|
|
|
@@ -104,6 +109,10 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|
|
setStore("todo", event.properties.sessionID, event.properties.todos)
|
|
|
break
|
|
|
|
|
|
+ case "session.diff":
|
|
|
+ setStore("session_diff", event.properties.sessionID, event.properties.diff)
|
|
|
+ break
|
|
|
+
|
|
|
case "session.deleted": {
|
|
|
const result = Binary.search(store.session, event.properties.info.id, (s) => s.id)
|
|
|
if (result.found) {
|
|
|
@@ -260,10 +269,11 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|
|
},
|
|
|
async sync(sessionID: string) {
|
|
|
const now = Date.now()
|
|
|
- const [session, messages, todo] = await Promise.all([
|
|
|
+ const [session, messages, todo, diff] = await Promise.all([
|
|
|
sdk.client.session.get({ path: { id: sessionID }, throwOnError: true }),
|
|
|
sdk.client.session.messages({ path: { id: sessionID } }),
|
|
|
sdk.client.session.todo({ path: { id: sessionID } }),
|
|
|
+ sdk.client.session.diff({ path: { id: sessionID } }),
|
|
|
])
|
|
|
console.log("fetched in " + (Date.now() - now), sessionID)
|
|
|
setStore(
|
|
|
@@ -276,6 +286,7 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|
|
for (const message of messages.data!) {
|
|
|
draft.part[message.info.id] = message.parts
|
|
|
}
|
|
|
+ draft.session_diff[sessionID] = diff.data ?? []
|
|
|
}),
|
|
|
)
|
|
|
console.log("synced in " + (Date.now() - now), sessionID)
|