feat: generate and edit conversation images across runtimes

Add model-controlled image invocation and read-only runtime assignments. Route image tools through Main so accepted operations retain their originating conversation when chat runtimes change, with saved references, cancellation, and manual recovery.

Keep Node hashing outside browser-shared contracts to restore production builds. Validation includes the production build, typecheck, lint, focused regressions, real Host transport checks, and two successful real image requests. Full UI-driven runtime switching acceptance remains documented as pending.

Release note: 开启图片模型的会话调用后,聊天助手可调用图片生成与编辑工具,Runtime 分配自动管理。图片成果保存在原会话,可继续修改,并独立显示生成状态和取消入口。
This commit is contained in:
mesalogo
2026-09-15 15:51:52 +08:00
parent e5aa9ed688
commit f8d07419d2
78 changed files with 2948 additions and 330 deletions
@@ -41,6 +41,64 @@ import { LocalRuntimeRegistry } from './local-runtime-registry'
import { createAgentRuntime } from './create-runtime'
import { defaultRuntimeSettings } from '../../shared/contracts'
import type { ResolvedRuntimeSettings } from '../runtime-settings-store'
import { AssistantDatabase } from '../assistant/assistant-database'
import { ImageGenerationService } from './image-generation-service'
vi.mock('electron', () => ({ nativeImage: {} }))
it('generates and edits durable images through the controlled Harness Main proxy and refreshes it in Ask', async () => {
const root = await realpath(await mkdtemp(join(tmpdir(), 'goodbuddy-dsh-images-')))
const database = new AssistantDatabase(join(root, 'assistant.sqlite'))
database.initialize(root)
const conversationId = crypto.randomUUID()
const profileId = crypto.randomUUID()
const fetcher = vi.fn<typeof fetch>(async () => Response.json({ data: [{ b64_json: 'iVBORw0KGgo=' }] }))
const service = new ImageGenerationService({ database, fetcher, getSettings: async () => ({ defaultImageModelProfileId: profileId, modelProfiles: [{
id: profileId, name: 'Image fixture', modelName: 'fixture', protocol: 'openai-images-generations',
allowConversationInvocation: true, baseUrl: 'https://image.test/v1', authentication: 'none'
}] }) })
let input: Record<string, unknown> = { intent: 'create', prompt: 'Blue circle' }
const inProcess = createInProcessLaunch(root, {
stream(options) {
const prompt = latestUserText(options)
const tool = options.tools?.find(tool => tool.name === 'generate_image')
if (prompt === 'ask-image') {
expect(tool).toBeUndefined()
return textResponse('Ask is read-only')
}
expect(tool).toBeDefined()
expect(tool?.description).toContain(profileId)
if (!toolResultText(options, prompt)) return toolCall(prompt, 'generate_image', input)
expect(toolResultText(options, prompt)).toContain('completed')
return textResponse('IMAGE_SAVED')
}
})
const runtime = new DeepSeekHarnessRuntime({ defaultWorkspace: root, baseUrl: 'https://chat.test/v1', model: 'fixture',
launch: inProcess.launch, credentialRefs: { [CREDENTIAL_REF]: 'fixture' }, toolProvider: new ModelToolProvider(root),
initializationTimeoutMs: 20_000, promptTimeoutMs: 20_000, shutdownTimeoutMs: 5_000 })
try {
for (const intent of ['create', 'edit'] as const) {
const messageId = crypto.randomUUID()
const requestId = crypto.randomUUID()
database.saveLocalConversations([{ header: { id: conversationId, title: 'Images', updatedAt: Date.now() },
messages: [{ id: messageId, role: 'assistant', content: '', createdAt: Date.now(), state: 'complete' }] }])
const events = await collect(runtime.run({ requestId, conversationId, prompt: `${intent}-${requestId}`, workMode: 'execute',
imageToolBinding: service.bind({ conversationId, messageId, requestId, workMode: 'execute' }) }, new AbortController().signal, async () => 'once'))
expect(events.at(-1)?.type).toBe('done')
const operation = database.getConversation(conversationId).messages.find(message => message.id === messageId)!.imageOperations![0]!
expect(operation.state).toBe('completed')
input = { intent: 'edit', prompt: 'Turn red', sourceArtifactIds: operation.artifactIds }
}
await collect(runtime.run({ requestId: crypto.randomUUID(), conversationId, prompt: 'ask-image', workMode: 'ask' }, new AbortController().signal))
expect(fetcher).toHaveBeenCalledTimes(2)
expect(String(fetcher.mock.calls[1]![0])).toMatch(/images\/edits$/u)
} finally {
await runtime.dispose()
await service.dispose()
database.close()
await rm(root, { recursive: true, force: true })
}
}, 60_000)
const CREDENTIAL_REF = 'GOODBUDDY_HARNESS_MODEL_API_KEY'
const SKILL_CALL_ID = 'e2e-skill-call'