Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions studio-app/src/StoryChat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import {
import { createPreviewChat } from './story-chat-preview.js';
import { createLiveChat } from './story-chat-client.js';
import { ACCEPT } from './story-chat-attach.js';

const MAX_MESSAGE_CHARS = 4000,
MAX_SCRIPT_CHARS = 20000;
import { AttachedFiles, PendingFiles, useAttachments } from './StoryChatAttachments.jsx';
import { createCloudClient } from './cloud-client.js';
import { agentLinkSearch } from './agent-navigation.js';
Expand Down Expand Up @@ -559,7 +562,12 @@ export default function StoryChat({ account, mode = 'preview', projectId = null
};
const [fresh, setFresh] = useState([]);
const [notice, setNotice] = useState('');
const attachments = useAttachments({ live, maxChars: 4000, setText, onNotice: setNotice });
const attachments = useAttachments({
live,
maxChars: MAX_SCRIPT_CHARS,
setText,
onNotice: setNotice,
});
const files = attachments.files;
const chat = useRef(null);
const thread = useRef(null);
Expand Down Expand Up @@ -679,7 +687,13 @@ export default function StoryChat({ account, mode = 'preview', projectId = null
const send = (value = text) => {
const message = value.trim();
if ((!message && !files.length) || state.busy || unavailable) return;
chat.current.send({ text: message, attachments: files }, emit);
if (message.length > MAX_SCRIPT_CHARS) {
setNotice(t('storyChat.textCut', { max: MAX_SCRIPT_CHARS }));
return;
}
// A long message is a script: it gets its own limit, and shots to check before anything is made.
const script = message.length > MAX_MESSAGE_CHARS;
chat.current.send({ text: message, attachments: files, script }, emit);
track('story_chat_message', { live, attachments: files.length });
setText('');
attachments.clear();
Expand Down Expand Up @@ -848,6 +862,7 @@ export default function StoryChat({ account, mode = 'preview', projectId = null
<div className="sc-welcome">
<h1>{t('storyChat.welcome')}</h1>
<p>{t('storyChat.welcomeHelp')}</p>
<p className="muted">{t('storyChat.scriptHelp')}</p>
<div className="sc-starters">
{starters.map(({ key, picture }) => (
<Button
Expand Down
3 changes: 3 additions & 0 deletions studio-app/src/i18n/storyChatCatalogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export const storyChatCatalogs = {
'storyChat.starter3': 'A bedtime story about a fox who can’t sleep',
'storyChat.placeholder': 'Describe your story, or ask for a change…',
'storyChat.attach': 'Add files',
'storyChat.scriptHelp':
'Have a script? Paste it below or drop in a text file, and you can check the shots first.',
'storyChat.attachTo': 'Where {name} goes',
'storyChat.attachLibrary': 'Story library',
'storyChat.uploadPhoto': 'Upload photo',
Expand Down Expand Up @@ -190,6 +192,7 @@ export const storyChatCatalogs = {
'storyChat.starter3': '一个睡不着的小狐狸的睡前故事',
'storyChat.placeholder': '说说你的故事,或者告诉我要改什么…',
'storyChat.attach': '添加文件',
'storyChat.scriptHelp': '已有剧本?粘贴到下面或拖入文本文件,可以先检查镜头。',
'storyChat.attachTo': '{name} 放到哪里',
'storyChat.attachLibrary': '故事素材库',
'storyChat.uploadPhoto': '上传照片',
Expand Down
8 changes: 6 additions & 2 deletions studio-app/src/story-chat-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export function createLiveChat({
load(await api.request(path + '/open', { method: 'POST', body: { language } }), emit);
}
},
async send({ text, attachments = [] }, emit) {
async send({ text, attachments = [], script = false }, emit) {
const id = turnId();
emit({ type: 'user.message', id: id + '-u', text, attachments });
emit({ type: 'turn.started' });
Expand All @@ -246,7 +246,11 @@ export function createLiveChat({
const note = attachmentNote(added, labels.t);
const value = await api.request(`/v1/story-chats/${encodeURIComponent(ident)}/turns`, {
method: 'POST',
body: { turn_id: id, text: [text, note].filter(Boolean).join('\n\n') },
body: {
turn_id: id,
text: [text, note].filter(Boolean).join('\n\n'),
...(script ? { script: true } : {}),
},
// A model turn can take 10–30 s; never give up before the server does.
timeoutMs: 120000,
});
Expand Down
Loading