Files
goodbuddy/src/shared/remote-image-tool-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

35 lines
1.4 KiB
TypeScript

import { z } from 'zod'
import { agentIdentifierSchema, positiveAgentSequenceSchema } from './agent-protocol/contracts'
import { imageOperationSchema, imageToolDescriptionLimit, imageToolInputSchema } from './image-generation-contracts'
export const remoteImageToolSchema = z.object({
channelId: agentIdentifierSchema,
channelEpoch: positiveAgentSequenceSchema,
description: z.string().min(1).max(imageToolDescriptionLimit)
}).strict()
export const remoteImageToolCallSchema = z.object({
callId: z.string().uuid(),
input: imageToolInputSchema
}).strict()
export const remoteImageToolReplySchema = z.object({
callId: z.string().uuid(),
result: imageOperationSchema.optional(),
error: z.string().max(4_000).optional()
}).strict()
// References and operation metadata only. Image bytes never cross this channel.
export const remoteImageToolMaximumBytes = 256 * 1024
export function encodeRemoteImageToolMessage(value: unknown): Uint8Array {
const bytes = new TextEncoder().encode(JSON.stringify(value))
if (bytes.byteLength > remoteImageToolMaximumBytes) throw new Error('Image tool message is too large')
return bytes
}
export function decodeRemoteImageToolMessage(bytes: Uint8Array): unknown {
if (bytes.byteLength > remoteImageToolMaximumBytes) throw new Error('Image tool message is too large')
return JSON.parse(new TextDecoder().decode(bytes)) as unknown
}