The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(agent): no "video generated" after a retry that never ran (D6)
purple98d365b2e408
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.tsindex 82a7b5ec..66633f50 100644--- a/src/hooks/useAgentChat.ts+++ b/src/hooks/useAgentChat.ts@@ -50,6 +50,7 @@ import { gatePlanTool, planToolAllowed } from '../lib/plan-gate'import { buildHermesToolPrompt, buildHermesToolResult, buildHermesToolCall, parseHermesToolCalls, stripToolCallTags, hasToolCallTags } from '../api/hermes-tool-calling'import { parseLooseToolCalls, stripMatchedCalls, stripToolCallText, repairToolCall } from '../lib/loose-tool-parse'import { isMediaTool, mediaCallSucceeded } from '../lib/media-result'+import { mediaTurnCaps, droppedMediaNote } from '../lib/media-turn-caps'import { isLocalModelByName } from '../api/agents/model-locality'import {mayRunInBackground,@@ -1575,13 +1576,13 @@ export function useAgentChat() {// order is never rebuilt from prose: it needs the customer's approval.const wantsImage = !opts?.createTools && (hintKind === 'image' || /\b(bild|bilder|foto|image|picture|pic|draw|zeichne|mal(e|en)?|grafik|illustration|render)\b/i.test(userPromptText))const wantsVideo = !opts?.createTools && (hintKind === 'video' || /\b(video|clip|animier\w*|animate|film|gif|bewegt|motion|mp4|webm)\b/i.test(userPromptText))- const maxImageGen = wantsVideo && !wantsImage ? 0 : 1// Video generation is turned OFF in the chat tools (video defaults to// 'blocked' + locked toggle, 2026-06-04). Respect that here so the// deterministic media-synthesis fallback below never force-creates a video- // the user disabled.+ // the user disabled. A message that names no medium ("try again" after a+ // declined call) leaves one clip open (D6, lib/media-turn-caps.ts).const videoAllowed = permissions.video !== 'blocked'- const maxVideoGen = wantsVideo && videoAllowed ? 1 : 0+ const { maxImage: maxImageGen, maxVideo: maxVideoGen } = mediaTurnCaps({ wantsImage, wantsVideo, videoAllowed })let imageGenDone = 0let videoGenDone = 0// Track whether the generated media was actually fed back to the model@@ -2460,6 +2461,7 @@ export function useAgentChat() {let blocked = falselet blockedNonMedia = falselet blockedCreate = false+ let droppedVideo = falselet createInTurn = 0const kept: ToolCall[] = []for (const tc of toolCalls) {@@ -2469,7 +2471,7 @@ export function useAgentChat() {} else if (name === 'image_generate') {if (allowImg > 0) { allowImg--; kept.push(tc) } else { blocked = true }} else if (name === 'video_generate') {- if (allowVid > 0) { allowVid--; kept.push(tc) } else { blocked = true }+ if (allowVid > 0) { allowVid--; kept.push(tc) } else { blocked = true; droppedVideo = true }} else if (executedCallKeys.has(callKey(tc))) {blocked = trueblockedNonMedia = true@@ -2504,7 +2506,8 @@ export function useAgentChat() {? 'Stop: you are repeating tool calls that already ran this turn — their results are shown above and have not changed. Do not call the same tool with the same arguments again. Use the results you already have and write your final answer now, without calling any tool.': blockedCreate? createCallSteer(createCalls)- : 'Stop, the media you were asked for is already created and shown. Write ONLY a short, friendly closing line to the user in their own language (e.g. that their picture/clip is ready). Do not output JSON, do not repeat this note, and do not call any tool.',+ // "already created" only when this turn did create it (D6).+ : droppedMediaNote({ imagesDone: imageGenDone, videosDone: videoGenDone, droppedVideo, videoAllowed }),} as ChatMessage)continue}diff --git a/src/lib/__tests__/media-turn-caps.test.ts b/src/lib/__tests__/media-turn-caps.test.tsnew file mode 100644index 00000000..dba4336a--- /dev/null+++ b/src/lib/__tests__/media-turn-caps.test.ts@@ -0,0 +1,52 @@+/**+ * D6 (Discord 05.11.2026): after a declined video_generate call and "try+ * again", the chat said "video generated" and there was no video. The retry+ * carried no video word, the turn's video limit was 0, the call was dropped,+ * and the model was told the media was "already created and shown".+ *+ * Run: npx vitest run src/lib/__tests__/media-turn-caps.test.ts+ */+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'+import { mediaTurnCaps, droppedMediaNote } from '../media-turn-caps'++describe('D6: what one agent turn may make', () => {+ it('"try again" after a declined clip leaves one clip open', () => {+ expect(mediaTurnCaps({ wantsImage: false, wantsVideo: false, videoAllowed: true }).maxVideo).toBe(1)+ })++ it('a message that asks for a picture only still makes no clip', () => {+ expect(mediaTurnCaps({ wantsImage: true, wantsVideo: false, videoAllowed: true })).toEqual({ maxImage: 1, maxVideo: 0 })+ })++ it('a clip request makes no detour picture, and video off makes no clip', () => {+ expect(mediaTurnCaps({ wantsImage: false, wantsVideo: true, videoAllowed: true })).toEqual({ maxImage: 0, maxVideo: 1 })+ expect(mediaTurnCaps({ wantsImage: false, wantsVideo: true, videoAllowed: false }).maxVideo).toBe(0)+ expect(mediaTurnCaps({ wantsImage: false, wantsVideo: false, videoAllowed: false }).maxVideo).toBe(0)+ })+})++describe('D6: the note after a dropped media call is true', () => {+ it('nothing made this turn: it says so and forbids claiming otherwise', () => {+ const note = droppedMediaNote({ imagesDone: 0, videosDone: 0, droppedVideo: true, videoAllowed: true })+ expect(note).not.toMatch(/already created/)+ expect(note).toMatch(/nothing was generated/)+ expect(note).toMatch(/Do not say that a picture or a clip was created/)+ })++ it('video switched off: the reason is named', () => {+ expect(droppedMediaNote({ imagesDone: 0, videosDone: 0, droppedVideo: true, videoAllowed: false })).toMatch(/switched off in the tool permissions/)+ })++ it('a second call after a delivered clip still gets the closing line', () => {+ expect(droppedMediaNote({ imagesDone: 0, videosDone: 1, droppedVideo: true, videoAllowed: true })).toMatch(/already created and shown/)+ })++ it('the agent loop takes both from here', () => {+ const src = readFileSync(resolve(__dirname, '../../hooks/useAgentChat.ts'), 'utf8')+ expect(src).toMatch(/mediaTurnCaps\(\{ wantsImage, wantsVideo, videoAllowed \}\)/)+ expect(src).toMatch(/droppedMediaNote\(\{ imagesDone: imageGenDone, videosDone: videoGenDone, droppedVideo, videoAllowed \}\)/)+ expect(src).not.toMatch(/'Stop, the media you were asked for is already created/)+ })+})diff --git a/src/lib/media-turn-caps.ts b/src/lib/media-turn-caps.tsnew file mode 100644index 00000000..def8cd10--- /dev/null+++ b/src/lib/media-turn-caps.ts@@ -0,0 +1,58 @@+/**+ * How many pictures and clips one agent turn may make, and what the model is+ * told when a call over that limit is dropped.+ *+ * Discord 05.11.2026 (D6): the user declined a video_generate call, then asked+ * to try again. The new message carried no video word ("try again", in Polish+ * too), so the turn's video limit was 0 and the call was dropped before it+ * ran. The model was then told "the media you were asked for is already+ * created and shown", and passed that on: the chat said "video generated",+ * and there was no video.+ *+ * Two rules now:+ * - A clip is held back only when this message plainly asks for a picture+ * and not a clip, or when video is switched off. A message that names no+ * medium ("again", "try again") leaves one clip open; the call still needs+ * the user's approval where the permissions ask for it.+ * - The note after a dropped call says "already created" only when this turn+ * did create something. Otherwise it says that nothing was made, and why.+ */++export interface MediaWants {+ /** This message (or the router's hint) asks for a picture. */+ wantsImage: boolean+ /** This message (or the router's hint) asks for a clip. */+ wantsVideo: boolean+ /** Video generation is not switched off in the tool permissions. */+ videoAllowed: boolean+}++/** The most pictures and clips this turn may make. */+export function mediaTurnCaps({ wantsImage, wantsVideo, videoAllowed }: MediaWants): { maxImage: number; maxVideo: number } {+ return {+ // A clip was asked for and no picture: a picture call is a detour.+ maxImage: wantsVideo && !wantsImage ? 0 : 1,+ // A picture was asked for and no clip, or video is off: no clip.+ maxVideo: videoAllowed && (wantsVideo || !wantsImage) ? 1 : 0,+ }+}++export interface DroppedMedia {+ /** Pictures and clips this turn did deliver. */+ imagesDone: number+ videosDone: number+ /** A video_generate call was among the dropped ones. */+ droppedVideo: boolean+ videoAllowed: boolean+}++/** What the model reads after every media call it made was dropped. */+export function droppedMediaNote({ imagesDone, videosDone, droppedVideo, videoAllowed }: DroppedMedia): string {+ if (imagesDone + videosDone > 0) {+ return 'Stop, the media you were asked for is already created and shown. Write ONLY a short, friendly closing line to the user in their own language (e.g. that their picture/clip is ready). Do not output JSON, do not repeat this note, and do not call any tool.'+ }+ const why = droppedVideo && !videoAllowed+ ? 'Video generation is switched off in the tool permissions, so no clip was made.'+ : 'That call did not run, so nothing was generated in this turn.'+ return `Stop: ${why} Do not say that a picture or a clip was created. Tell the user in one short sentence, in their own language, that nothing was generated, and ask what they want made. Do not output JSON and do not call any tool.`+}