Skip to content

Commit 203d675

Browse files
committed
sync
1 parent 53f212c commit 203d675

3 files changed

Lines changed: 922 additions & 40 deletions

File tree

packages/opencode/src/cli/cmd/tui/context/sync-v2.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ function activeAssistant(messages: SessionMessage[]) {
1919

2020
function latestTool(assistant: SessionMessageAssistant | undefined, callID?: string) {
2121
return assistant?.content.findLast(
22-
(item): item is SessionMessageAssistantTool =>
23-
item.type === "tool" && (callID === undefined || item.callID === callID),
22+
(item): item is SessionMessageAssistantTool => item.type === "tool" && (callID === undefined || item.id === callID),
2423
)
2524
}
2625

@@ -30,7 +29,7 @@ function latestText(assistant: SessionMessageAssistant | undefined) {
3029

3130
function latestReasoning(assistant: SessionMessageAssistant | undefined, reasoningID: string) {
3231
return assistant?.content.findLast(
33-
(item): item is SessionMessageAssistantReasoning => item.type === "reasoning" && item.reasoningID === reasoningID,
32+
(item): item is SessionMessageAssistantReasoning => item.type === "reasoning" && item.id === reasoningID,
3433
)
3534
}
3635

@@ -90,6 +89,8 @@ export const { use: useSyncV2, provider: SyncProviderV2 } = createSimpleContext(
9089
draft.push({
9190
id: event.properties.id,
9291
type: "assistant",
92+
agent: event.properties.agent,
93+
model: event.properties.model,
9394
content: [],
9495
snapshot: event.properties.snapshot ? { start: event.properties.snapshot } : undefined,
9596
time: { created: event.properties.timestamp },
@@ -101,6 +102,7 @@ export const { use: useSyncV2, provider: SyncProviderV2 } = createSimpleContext(
101102
const currentAssistant = activeAssistant(draft)
102103
if (!currentAssistant) return
103104
currentAssistant.time.completed = event.properties.timestamp
105+
currentAssistant.finish = event.properties.finish
104106
currentAssistant.cost = event.properties.cost
105107
currentAssistant.tokens = event.properties.tokens
106108
if (event.properties.snapshot)
@@ -128,7 +130,7 @@ export const { use: useSyncV2, provider: SyncProviderV2 } = createSimpleContext(
128130
update(event.properties.sessionID, (draft) => {
129131
activeAssistant(draft)?.content.push({
130132
type: "tool",
131-
callID: event.properties.callID,
133+
id: event.properties.callID,
132134
name: event.properties.name,
133135
time: { created: event.properties.timestamp },
134136
state: { status: "pending", input: "" },
@@ -148,6 +150,7 @@ export const { use: useSyncV2, provider: SyncProviderV2 } = createSimpleContext(
148150
const match = latestTool(activeAssistant(draft), event.properties.callID)
149151
if (!match) return
150152
match.time.ran = event.properties.timestamp
153+
match.provider = event.properties.provider
151154
match.state = { status: "running", input: event.properties.input, structured: {}, content: [] }
152155
})
153156
break
@@ -169,6 +172,8 @@ export const { use: useSyncV2, provider: SyncProviderV2 } = createSimpleContext(
169172
structured: event.properties.structured,
170173
content: [...event.properties.content],
171174
}
175+
match.provider = event.properties.provider
176+
match.time.completed = event.properties.timestamp
172177
})
173178
break
174179
case "session.next.tool.error":
@@ -182,13 +187,15 @@ export const { use: useSyncV2, provider: SyncProviderV2 } = createSimpleContext(
182187
structured: match.state.structured,
183188
content: match.state.content,
184189
}
190+
match.provider = event.properties.provider
191+
match.time.completed = event.properties.timestamp
185192
})
186193
break
187194
case "session.next.reasoning.started":
188195
update(event.properties.sessionID, (draft) => {
189196
activeAssistant(draft)?.content.push({
190197
type: "reasoning",
191-
reasoningID: event.properties.reasoningID,
198+
id: event.properties.reasoningID,
192199
text: "",
193200
})
194201
})

0 commit comments

Comments
 (0)