Files
goodbuddy/src/shared/image-generation-contracts.ts
T
mesalogo f8d07419d2 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 分配自动管理。图片成果保存在原会话,可继续修改,并独立显示生成状态和取消入口。
2026-09-15 15:51:52 +08:00

46 lines
2.1 KiB
TypeScript

import { z } from 'zod'
export const imageToolInputSchema = z.object({
prompt: z.string().trim().min(1).max(32_000),
intent: z.enum(['create', 'edit']),
modelProfileId: z.string().uuid().optional(),
sourceArtifactIds: z.array(z.string().uuid()).max(8).default([]),
quality: z.enum(['auto', 'low', 'medium', 'high']).optional()
}).strict().superRefine((input, context) => {
if ((input.intent === 'edit') !== (input.sourceArtifactIds.length > 0)) {
context.addIssue({ code: 'custom', message: 'Editing requires source images; creating must not include source images.' })
}
})
export type ImageToolInput = z.infer<typeof imageToolInputSchema>
export const imageOperationSchema = z.object({
id: z.string().uuid(),
conversationId: z.string(),
messageId: z.string(),
requestId: z.string(),
callId: z.string(),
modelProfileId: z.string().uuid(),
modelName: z.string(),
modelProfileName: z.string().optional(),
input: imageToolInputSchema,
state: z.enum(['running', 'saving', 'completed', 'cancelling', 'stopped', 'failed', 'unconfirmed']),
createdAt: z.number(),
updatedAt: z.number(),
artifactIds: z.array(z.string().uuid()).default([]),
error: z.string().optional(),
cancellationRequested: z.boolean().optional()
}).strict()
export type ImageOperation = z.infer<typeof imageOperationSchema>
/** Bound by Main/Agent transport, never accepted as model tool arguments. */
export type ImageRequestContext = {
conversationId: string
messageId: string
requestId: string
workMode: 'ask' | 'execute'
}
export const imageToolName = 'generate_image' as const
export const imageToolDescriptionLimit = 16_000
export const imageToolDescription = 'Generate or edit an image using a configured image model. Use intent=create for a new unrelated image, or intent=edit with explicit sourceArtifactIds. Never invent profile or artifact IDs. Clarify ambiguous references. A failed edit must not be replaced by generation. Results contain operation and artifact references, not image bytes. Do not retry a paid request automatically. A running operation continues after this chat stops; inspect its conversation card for completion.'