Spaces:
Sleeping
Sleeping
Download src/studio-agent/runtime/execution/part-synchronizer.ts from Bin29/ManimCat-show: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/spaces/Bin29/ManimCat-show/resolve/main/src/studio-agent/runtime/execution/part-synchronizer.ts
- Command line
-
hf download hf://spaces/Bin29/ManimCat-show/src/studio-agent/runtime/execution/part-synchronizer.ts
-
curl -L -o part-synchronizer.ts https://huggingface.co/spaces/Bin29/ManimCat-show/resolve/main/src/studio-agent/runtime/execution/part-synchronizer.ts
1.64 kB
| import type { | |
| StudioAssistantMessage, | |
| StudioMessagePart, | |
| StudioMessageStore, | |
| StudioPartStore | |
| } from '../../domain/types' | |
| import { replaceMessagePart } from '../../domain/factories' | |
| export class StudioPartSynchronizer { | |
| constructor( | |
| private readonly messageStore: StudioMessageStore, | |
| private readonly partStore: StudioPartStore | |
| ) {} | |
| async appendPart( | |
| assistantMessage: StudioAssistantMessage, | |
| part: StudioMessagePart | |
| ): Promise<StudioMessagePart> { | |
| await this.partStore.create(part) | |
| const currentMessage = await this.messageStore.getById(assistantMessage.id) | |
| const currentParts = currentMessage && currentMessage.role === 'assistant' | |
| ? currentMessage.parts | |
| : assistantMessage.parts | |
| const refreshed = replaceMessagePart(currentParts, part) | |
| const updated = await this.messageStore.updateAssistantMessage(assistantMessage.id, { | |
| parts: refreshed | |
| }) | |
| assistantMessage.parts = updated?.parts ?? refreshed | |
| return part | |
| } | |
| async updatePart(partId: string, patch: Partial<StudioMessagePart> | StudioMessagePart): Promise<void> { | |
| const current = await this.partStore.getById(partId) | |
| if (!current) { | |
| return | |
| } | |
| const next = { | |
| ...current, | |
| ...patch | |
| } as StudioMessagePart | |
| await this.partStore.update(partId, next) | |
| const message = await this.messageStore.getById(current.messageId) | |
| if (!message || message.role !== 'assistant') { | |
| return | |
| } | |
| const refreshed = replaceMessagePart(message.parts, next) | |
| await this.messageStore.updateAssistantMessage(message.id, { | |
| parts: refreshed | |
| }) | |
| } | |
| } | |