Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

chore: remove + skip button in the chat panel

Etienne Lescot1a505ade49bf
diff --git a/src/components/ai-edition/LeftPanel.tsx b/src/components/ai-edition/LeftPanel.tsx
index 3bb5024a1..f140e15e2 100644
--- a/src/components/ai-edition/LeftPanel.tsx
+++ b/src/components/ai-edition/LeftPanel.tsx
@@ -7,12 +7,10 @@ import { useScopedT } from "@/contexts/I18nContext";
import { type AxcutAsset, ensureDocument } from "@/lib/ai-edition/schema";
import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
import { useChatPromptBus } from "@/lib/ai-edition/store/useChatPromptBus";
-import { useOptimisticTimelineOps } from "@/lib/ai-edition/store/useOptimisticTimelineOps";
import { nativeBridgeClient } from "@/native/client";
import type {
AiEditionLlmConfig,
AiEditionToolCallSummary,
- AxcutTimelineOperation,
} from "@/native/contracts";
import { formatBytes } from "@/utils/formatBytes";
import {
@@ -1139,32 +1137,6 @@ function ChatStripPanel() {
[editingTitle, handleRename, cancelEditTitle],
);
- const { queue: queueTimelineOp, busy: queueBusy } = useOptimisticTimelineOps(
- projectId,
- activeSessionId,
- );
- const runAddTrim = useCallback(() => {
- const raw = window.prompt(t("chat.addSkipRangePrompt"), "5-8");
- if (!raw) return;
- const m = raw.match(/^\s*(\d+(?:\.\d+)?)\s*[-–]\s*(\d+(?:\.\d+)?)\s*$/);
- if (!m) {
- toast.error(t("chat.addSkipRangeFormatError"));
- return;
- }
- const startSec = Number(m[1]);
- const endSec = Number(m[2]);
- if (!Number.isFinite(startSec) || !Number.isFinite(endSec) || endSec <= startSec) {
- toast.error(t("chat.addSkipRangeOrderError"));
- return;
- }
- const op: AxcutTimelineOperation = {
- type: "add_trim_range",
- startSec,
- endSec,
- };
- void queueTimelineOp(op, t("chat.addSkipRangeApplied", { startSec, endSec }));
- }, [queueTimelineOp, t]);
-
return (
<aside className={styles.panel}>
<div className={styles.panelHeader}>
@@ -1402,25 +1374,6 @@ function ChatStripPanel() {
<path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2" />
</svg>
</button>
- <button
- type="button"
- title={t("chat.addSkipRange")}
- aria-label={t("chat.addSkipRange")}
- disabled={!activeSessionId || queueBusy}
- onClick={runAddTrim}
- style={{
- background: "transparent",
- border: "1px solid var(--border-soft)",
- borderRadius: "var(--r-sm)",
- color: "var(--fg-2)",
- font: "500 10px var(--font-body)",
- padding: "2px 6px",
- cursor: queueBusy ? "wait" : "pointer",
- whiteSpace: "nowrap",
- }}
- >
- {t("chat.skipButtonShort")}
- </button>
</div>
) : null}
</div>
diff --git a/src/i18n/locales/ar/editor.json b/src/i18n/locales/ar/editor.json
index 4e05f4643..bf035d34f 100644
--- a/src/i18n/locales/ar/editor.json
+++ b/src/i18n/locales/ar/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "تعذّر حذف المحادثة",
"renameSessionFailed": "تعذّر إعادة تسمية المحادثة",
"reasoningEffortUpdateFailed": "تعذّر تحديث جهد الاستدلال",
- "addSkipRangePrompt": "إضافة نطاق تخطٍّ\nالتنسيق: startSec-endSec (مثال: 1.2-3.4)",
- "addSkipRangeFormatError": "استخدم startSec-endSec، مثال: 1.2-3.4",
- "addSkipRangeOrderError": "يجب أن يكون endSec أكبر من startSec.",
- "addSkipRangeApplied": "تمت إضافة تخطٍّ {{startSec}}–{{endSec}} ثانية.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} رمز مقدّر",
"contextPercent": "{{percent}}% من السياق",
"compactContext": "ضغط السياق",
@@ -253,8 +249,6 @@
"renameConversation": "إعادة تسمية المحادثة",
"deleteConversation": "حذف المحادثة",
"confirmDeleteConversation": "حذف \"{{title}}\"؟",
- "addSkipRange": "إضافة نطاق تخطٍّ",
- "skipButtonShort": "+ تخطٍّ",
"emptyState": "لا توجد رسائل بعد. اطلب من الوكيل قص الصمت أو تقليص الوقفات أو إضافة ترجمات.",
"welcome": {
"title": "أحضر ذكاءك الاصطناعي الخاص",
diff --git a/src/i18n/locales/en/editor.json b/src/i18n/locales/en/editor.json
index 5806e3adc..90a5f02f9 100644
--- a/src/i18n/locales/en/editor.json
+++ b/src/i18n/locales/en/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "Could not delete conversation",
"renameSessionFailed": "Could not rename conversation",
"reasoningEffortUpdateFailed": "Could not update reasoning effort",
- "addSkipRangePrompt": "Add skip range\nFormat: startSec-endSec (e.g. 1.2-3.4)",
- "addSkipRangeFormatError": "Use startSec-endSec, e.g. 1.2-3.4",
- "addSkipRangeOrderError": "endSec must be greater than startSec.",
- "addSkipRangeApplied": "Added skip {{startSec}}–{{endSec}}s.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} estimated tokens",
"contextPercent": "{{percent}}% context",
"compactContext": "Compact context",
@@ -253,8 +249,6 @@
"renameConversation": "Rename conversation",
"deleteConversation": "Delete conversation",
"confirmDeleteConversation": "Delete \"{{title}}\"?",
- "addSkipRange": "Add skip range",
- "skipButtonShort": "+ skip",
"emptyState": "No messages yet. Ask the agent to cut silences, tighten pauses, or add captions.",
"welcome": {
"title": "Bring your own AI",
diff --git a/src/i18n/locales/es/editor.json b/src/i18n/locales/es/editor.json
index d7c2df0bf..09219b0c6 100644
--- a/src/i18n/locales/es/editor.json
+++ b/src/i18n/locales/es/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "No se pudo eliminar la conversación",
"renameSessionFailed": "No se pudo renombrar la conversación",
"reasoningEffortUpdateFailed": "No se pudo actualizar el esfuerzo de razonamiento",
- "addSkipRangePrompt": "Añadir rango de salto\nFormato: startSec-endSec (p. ej. 1.2-3.4)",
- "addSkipRangeFormatError": "Usa startSec-endSec, p. ej. 1.2-3.4",
- "addSkipRangeOrderError": "endSec debe ser mayor que startSec.",
- "addSkipRangeApplied": "Se añadió un salto de {{startSec}}–{{endSec}}s.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} tokens estimados",
"contextPercent": "{{percent}}% de contexto",
"compactContext": "Compactar contexto",
@@ -253,8 +249,6 @@
"renameConversation": "Renombrar conversación",
"deleteConversation": "Eliminar conversación",
"confirmDeleteConversation": "¿Eliminar \"{{title}}\"?",
- "addSkipRange": "Añadir rango de salto",
- "skipButtonShort": "+ salto",
"emptyState": "Aún no hay mensajes. Pide al agente que corte silencios, ajuste pausas o añada subtítulos.",
"welcome": {
"title": "Trae tu propia IA",
diff --git a/src/i18n/locales/fr/editor.json b/src/i18n/locales/fr/editor.json
index e3a8dbb35..8e463b669 100644
--- a/src/i18n/locales/fr/editor.json
+++ b/src/i18n/locales/fr/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "Impossible de supprimer la conversation",
"renameSessionFailed": "Impossible de renommer la conversation",
"reasoningEffortUpdateFailed": "Impossible de mettre à jour l'effort de raisonnement",
- "addSkipRangePrompt": "Ajouter une plage à ignorer\nFormat : startSec-endSec (ex. 1.2-3.4)",
- "addSkipRangeFormatError": "Utilisez startSec-endSec, ex. 1.2-3.4",
- "addSkipRangeOrderError": "endSec doit être supérieur à startSec.",
- "addSkipRangeApplied": "Plage ignorée ajoutée {{startSec}}–{{endSec}}s.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} jetons estimés",
"contextPercent": "{{percent}}% du contexte",
"compactContext": "Compacter le contexte",
@@ -253,8 +249,6 @@
"renameConversation": "Renommer la conversation",
"deleteConversation": "Supprimer la conversation",
"confirmDeleteConversation": "Supprimer « {{title}} » ?",
- "addSkipRange": "Ajouter une plage à ignorer",
- "skipButtonShort": "+ saut",
"emptyState": "Aucun message pour l'instant. Demandez à l'agent de couper les silences, resserrer les pauses ou ajouter des sous-titres.",
"welcome": {
"title": "Apportez votre IA",
diff --git a/src/i18n/locales/it/editor.json b/src/i18n/locales/it/editor.json
index fe0638f79..0f7fbe749 100644
--- a/src/i18n/locales/it/editor.json
+++ b/src/i18n/locales/it/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "Impossibile eliminare la conversazione",
"renameSessionFailed": "Impossibile rinominare la conversazione",
"reasoningEffortUpdateFailed": "Impossibile aggiornare lo sforzo di ragionamento",
- "addSkipRangePrompt": "Aggiungi intervallo da saltare\nFormato: startSec-endSec (es. 1.2-3.4)",
- "addSkipRangeFormatError": "Usa startSec-endSec, es. 1.2-3.4",
- "addSkipRangeOrderError": "endSec deve essere maggiore di startSec.",
- "addSkipRangeApplied": "Aggiunto salto {{startSec}}–{{endSec}}s.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} token stimati",
"contextPercent": "{{percent}}% di contesto",
"compactContext": "Comprimi contesto",
@@ -253,8 +249,6 @@
"renameConversation": "Rinomina conversazione",
"deleteConversation": "Elimina conversazione",
"confirmDeleteConversation": "Eliminare \"{{title}}\"?",
- "addSkipRange": "Aggiungi intervallo da saltare",
- "skipButtonShort": "+ salto",
"emptyState": "Nessun messaggio ancora. Chiedi all'agente di tagliare i silenzi, stringere le pause o aggiungere sottotitoli.",
"welcome": {
"title": "Porta la tua IA",
diff --git a/src/i18n/locales/ja-JP/editor.json b/src/i18n/locales/ja-JP/editor.json
index 2e87b27f1..0b5055905 100644
--- a/src/i18n/locales/ja-JP/editor.json
+++ b/src/i18n/locales/ja-JP/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "会話を削除できませんでした",
"renameSessionFailed": "会話の名前を変更できませんでした",
"reasoningEffortUpdateFailed": "推論の労力を更新できませんでした",
- "addSkipRangePrompt": "スキップ範囲を追加\n形式:startSec-endSec(例:1.2-3.4)",
- "addSkipRangeFormatError": "startSec-endSec の形式を使用してください(例:1.2-3.4)",
- "addSkipRangeOrderError": "endSec は startSec より大きくする必要があります。",
- "addSkipRangeApplied": "{{startSec}}–{{endSec}}秒のスキップを追加しました。",
"contextTooltip": "推定トークン数 {{usedTokens}} / {{budgetTokens}}",
"contextPercent": "コンテキスト {{percent}}%",
"compactContext": "コンテキストを圧縮",
@@ -253,8 +249,6 @@
"renameConversation": "会話の名前を変更",
"deleteConversation": "会話を削除",
"confirmDeleteConversation": "「{{title}}」を削除しますか?",
- "addSkipRange": "スキップ範囲を追加",
- "skipButtonShort": "+ スキップ",
"emptyState": "まだメッセージはありません。エージェントに無音のカット、間の調整、字幕の追加を依頼してみましょう。",
"welcome": {
"title": "自分のAIを持ち込もう",
diff --git a/src/i18n/locales/ko-KR/editor.json b/src/i18n/locales/ko-KR/editor.json
index b50fd002d..4e97f0736 100644
--- a/src/i18n/locales/ko-KR/editor.json
+++ b/src/i18n/locales/ko-KR/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "대화를 삭제할 수 없습니다",
"renameSessionFailed": "대화 이름을 변경할 수 없습니다",
"reasoningEffortUpdateFailed": "추론 노력 수준을 업데이트할 수 없습니다",
- "addSkipRangePrompt": "건너뛸 구간 추가\n형식: startSec-endSec (예: 1.2-3.4)",
- "addSkipRangeFormatError": "startSec-endSec 형식을 사용하세요 (예: 1.2-3.4)",
- "addSkipRangeOrderError": "endSec은 startSec보다 커야 합니다.",
- "addSkipRangeApplied": "{{startSec}}–{{endSec}}초 구간 건너뛰기를 추가했습니다.",
"contextTooltip": "예상 토큰 {{usedTokens}} / {{budgetTokens}}",
"contextPercent": "컨텍스트 {{percent}}%",
"compactContext": "컨텍스트 압축",
@@ -253,8 +249,6 @@
"renameConversation": "대화 이름 변경",
"deleteConversation": "대화 삭제",
"confirmDeleteConversation": "\"{{title}}\"을(를) 삭제할까요?",
- "addSkipRange": "건너뛸 구간 추가",
- "skipButtonShort": "+ 건너뛰기",
"emptyState": "아직 메시지가 없습니다. 에이전트에게 무음 구간 자르기, 일시정지 조이기, 자막 추가를 요청해 보세요.",
"welcome": {
"title": "내 AI를 가져오세요",
diff --git a/src/i18n/locales/pt-BR/editor.json b/src/i18n/locales/pt-BR/editor.json
index dfdc18cfe..63e56581f 100644
--- a/src/i18n/locales/pt-BR/editor.json
+++ b/src/i18n/locales/pt-BR/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "Não foi possível excluir a conversa",
"renameSessionFailed": "Não foi possível renomear a conversa",
"reasoningEffortUpdateFailed": "Não foi possível atualizar o esforço de raciocínio",
- "addSkipRangePrompt": "Adicionar intervalo a pular\nFormato: startSec-endSec (ex.: 1.2-3.4)",
- "addSkipRangeFormatError": "Use startSec-endSec, ex.: 1.2-3.4",
- "addSkipRangeOrderError": "endSec deve ser maior que startSec.",
- "addSkipRangeApplied": "Salto de {{startSec}}–{{endSec}}s adicionado.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} tokens estimados",
"contextPercent": "{{percent}}% de contexto",
"compactContext": "Compactar contexto",
@@ -253,8 +249,6 @@
"renameConversation": "Renomear conversa",
"deleteConversation": "Excluir conversa",
"confirmDeleteConversation": "Excluir \"{{title}}\"?",
- "addSkipRange": "Adicionar intervalo a pular",
- "skipButtonShort": "+ pular",
"emptyState": "Ainda não há mensagens. Peça ao agente para cortar silêncios, apertar pausas ou adicionar legendas.",
"welcome": {
"title": "Traga a sua própria IA",
diff --git a/src/i18n/locales/ru/editor.json b/src/i18n/locales/ru/editor.json
index f2861918b..672207648 100644
--- a/src/i18n/locales/ru/editor.json
+++ b/src/i18n/locales/ru/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "Не удалось удалить беседу",
"renameSessionFailed": "Не удалось переименовать беседу",
"reasoningEffortUpdateFailed": "Не удалось обновить уровень рассуждений",
- "addSkipRangePrompt": "Добавить диапазон пропуска\nФормат: startSec-endSec (напр. 1.2-3.4)",
- "addSkipRangeFormatError": "Используйте startSec-endSec, напр. 1.2-3.4",
- "addSkipRangeOrderError": "endSec должен быть больше startSec.",
- "addSkipRangeApplied": "Добавлен пропуск {{startSec}}–{{endSec}} с.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} расчётных токенов",
"contextPercent": "{{percent}}% контекста",
"compactContext": "Сжать контекст",
@@ -253,8 +249,6 @@
"renameConversation": "Переименовать беседу",
"deleteConversation": "Удалить беседу",
"confirmDeleteConversation": "Удалить «{{title}}»?",
- "addSkipRange": "Добавить диапазон пропуска",
- "skipButtonShort": "+ пропуск",
"emptyState": "Пока нет сообщений. Попросите агента вырезать паузы, уплотнить их или добавить субтитры.",
"welcome": {
"title": "Подключите свой ИИ",
diff --git a/src/i18n/locales/tr/editor.json b/src/i18n/locales/tr/editor.json
index e5054501b..c683d9273 100644
--- a/src/i18n/locales/tr/editor.json
+++ b/src/i18n/locales/tr/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "Konuşma silinemedi",
"renameSessionFailed": "Konuşma yeniden adlandırılamadı",
"reasoningEffortUpdateFailed": "Akıl yürütme çabası güncellenemedi",
- "addSkipRangePrompt": "Atlama aralığı ekle\nBiçim: startSec-endSec (örn. 1.2-3.4)",
- "addSkipRangeFormatError": "startSec-endSec kullanın, örn. 1.2-3.4",
- "addSkipRangeOrderError": "endSec, startSec'ten büyük olmalıdır.",
- "addSkipRangeApplied": "{{startSec}}–{{endSec}} sn atlama eklendi.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} tahmini belirteç",
"contextPercent": "%{{percent}} bağlam",
"compactContext": "Bağlamı sıkıştır",
@@ -253,8 +249,6 @@
"renameConversation": "Konuşmayı yeniden adlandır",
"deleteConversation": "Konuşmayı sil",
"confirmDeleteConversation": "\"{{title}}\" silinsin mi?",
- "addSkipRange": "Atlama aralığı ekle",
- "skipButtonShort": "+ atla",
"emptyState": "Henüz mesaj yok. Aracıdan sessizlikleri kesmesini, duraklamaları sıkılaştırmasını veya altyazı eklemesini isteyin.",
"welcome": {
"title": "Kendi yapay zekanızı getirin",
diff --git a/src/i18n/locales/vi/editor.json b/src/i18n/locales/vi/editor.json
index e79a60ac4..34e86cc22 100644
--- a/src/i18n/locales/vi/editor.json
+++ b/src/i18n/locales/vi/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "Không thể xóa cuộc trò chuyện",
"renameSessionFailed": "Không thể đổi tên cuộc trò chuyện",
"reasoningEffortUpdateFailed": "Không thể cập nhật mức độ suy luận",
- "addSkipRangePrompt": "Thêm khoảng bỏ qua\nĐịnh dạng: startSec-endSec (vd. 1.2-3.4)",
- "addSkipRangeFormatError": "Dùng định dạng startSec-endSec, vd. 1.2-3.4",
- "addSkipRangeOrderError": "endSec phải lớn hơn startSec.",
- "addSkipRangeApplied": "Đã thêm khoảng bỏ qua {{startSec}}–{{endSec}}s.",
"contextTooltip": "{{usedTokens}} / {{budgetTokens}} token ước tính",
"contextPercent": "{{percent}}% ngữ cảnh",
"compactContext": "Nén ngữ cảnh",
@@ -253,8 +249,6 @@
"renameConversation": "Đổi tên cuộc trò chuyện",
"deleteConversation": "Xóa cuộc trò chuyện",
"confirmDeleteConversation": "Xóa \"{{title}}\"?",
- "addSkipRange": "Thêm khoảng bỏ qua",
- "skipButtonShort": "+ bỏ qua",
"emptyState": "Chưa có tin nhắn nào. Yêu cầu tác nhân cắt khoảng lặng, rút ngắn khoảng dừng hoặc thêm phụ đề.",
"welcome": {
"title": "Mang theo AI của bạn",
diff --git a/src/i18n/locales/zh-CN/editor.json b/src/i18n/locales/zh-CN/editor.json
index d0bea6829..8afd7be95 100644
--- a/src/i18n/locales/zh-CN/editor.json
+++ b/src/i18n/locales/zh-CN/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "无法删除对话",
"renameSessionFailed": "无法重命名对话",
"reasoningEffortUpdateFailed": "无法更新推理强度",
- "addSkipRangePrompt": "添加跳过范围\n格式:startSec-endSec(例如 1.2-3.4)",
- "addSkipRangeFormatError": "请使用 startSec-endSec 格式,例如 1.2-3.4",
- "addSkipRangeOrderError": "endSec 必须大于 startSec。",
- "addSkipRangeApplied": "已添加跳过 {{startSec}}–{{endSec}} 秒。",
"contextTooltip": "预估 {{usedTokens}} / {{budgetTokens}} 个 token",
"contextPercent": "上下文 {{percent}}%",
"compactContext": "压缩上下文",
@@ -253,8 +249,6 @@
"renameConversation": "重命名对话",
"deleteConversation": "删除对话",
"confirmDeleteConversation": "删除 \"{{title}}\"?",
- "addSkipRange": "添加跳过范围",
- "skipButtonShort": "+ 跳过",
"emptyState": "暂无消息。可以让代理剪掉静音、收紧停顿或添加字幕。",
"welcome": {
"title": "自带你的 AI",
diff --git a/src/i18n/locales/zh-TW/editor.json b/src/i18n/locales/zh-TW/editor.json
index c3ee62bb2..7d4db14ff 100644
--- a/src/i18n/locales/zh-TW/editor.json
+++ b/src/i18n/locales/zh-TW/editor.json
@@ -238,10 +238,6 @@
"deleteSessionFailed": "無法刪除對話",
"renameSessionFailed": "無法重新命名對話",
"reasoningEffortUpdateFailed": "無法更新推理強度",
- "addSkipRangePrompt": "新增跳過範圍\n格式:startSec-endSec(例如 1.2-3.4)",
- "addSkipRangeFormatError": "請使用 startSec-endSec 格式,例如 1.2-3.4",
- "addSkipRangeOrderError": "endSec 必須大於 startSec。",
- "addSkipRangeApplied": "已新增跳過 {{startSec}}–{{endSec}} 秒。",
"contextTooltip": "預估 {{usedTokens}} / {{budgetTokens}} 個權杖",
"contextPercent": "上下文 {{percent}}%",
"compactContext": "壓縮上下文",
@@ -253,8 +249,6 @@
"renameConversation": "重新命名對話",
"deleteConversation": "刪除對話",
"confirmDeleteConversation": "刪除「{{title}}」?",
- "addSkipRange": "新增跳過範圍",
- "skipButtonShort": "+ 跳過",
"emptyState": "尚無訊息。可以請代理剪掉靜音、收緊停頓或加入字幕。",
"welcome": {
"title": "自帶你的 AI",
diff --git a/src/lib/ai-edition/store/useOptimisticTimelineOps.ts b/src/lib/ai-edition/store/useOptimisticTimelineOps.ts
deleted file mode 100644
index 5e981ce02..000000000
--- a/src/lib/ai-edition/store/useOptimisticTimelineOps.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-// ponytail: optimistic timeline-ops state machine. Mirrors axcut's
-// `queueTimelineOperation` flow but on a smaller surface: we read the
-// project store, apply the op locally for instant UI feedback, fire
-// the IPC, then either commit the server's authoritative document or
-// roll back on failure. Session messages aren't touched locally — the
-// server appends the summary message before returning.
-
-import { useCallback, useState } from "react";
-import { toast } from "sonner";
-import { nativeBridgeClient } from "@/native/client";
-import type { AxcutTimelineOperation } from "@/native/contracts";
-import { applyTimelineOperation } from "../document/operations";
-import type { AxcutDocument } from "../schema";
-import { useProjectStore } from "./projectStore";
-
-export interface OptimisticTimelineOps {
- queue: (operation: AxcutTimelineOperation, conversationMessage: string) => Promise<void>;
- busy: boolean;
-}
-
-export function useOptimisticTimelineOps(
- projectId: string | null,
- sessionId: string | null,
-): OptimisticTimelineOps {
- const [busy, setBusy] = useState(false);
-
- const queue = useCallback(
- async (operation: AxcutTimelineOperation, conversationMessage: string) => {
- if (!projectId || !sessionId) {
- toast.error("Open a project to run a timeline operation.");
- return;
- }
- const store = useProjectStore.getState();
- const previous = store.document;
- if (!previous) {
- toast.error("No project document loaded yet.");
- return;
- }
- const optimistic = applyTimelineOperation(previous, operation).document;
- store.setDocument(optimistic);
- setBusy(true);
- try {
- const result = await nativeBridgeClient.aiEdition.runTimelineOperation(
- projectId,
- sessionId,
- operation,
- conversationMessage,
- );
- if (!result.success) {
- store.setDocument(previous);
- toast.error("Timeline edit failed", { description: result.error });
- return;
- }
- // ponytail: keep the optimistic doc on failure-free success. The
- // server-applied doc is byte-identical in the happy path; only
- // when normalisation diverges do we need to swap.
- const serverDoc = result.result.document as AxcutDocument;
- store.setDocument(serverDoc);
- toast.success(result.result.summary);
- } catch (err) {
- store.setDocument(previous);
- toast.error("Timeline edit failed", {
- description: err instanceof Error ? err.message : String(err),
- });
- } finally {
- setBusy(false);
- }
- },
- [projectId, sessionId],
- );
-
- return { queue, busy };
-}