feat: complete TASK-WP2-06 generation terminal states

This commit is contained in:
suyx
2026-08-03 01:06:28 +08:00
parent c8643c080d
commit 2bb4f86d04
18 changed files with 1419 additions and 14 deletions
+54
View File
@@ -0,0 +1,54 @@
import type { GenerationErrorCategory } from "./generation-error-registry.js";
export interface GenerationAdapterRequest {
configSnapshot: Readonly<Record<string, unknown>>;
generationId: string;
modelId: string;
prompt: string;
ratio: "3:4" | "1:1" | "4:3" | "9:16";
referenceAssetIds: readonly string[];
}
export interface NormalizedGenerationOutput {
bytes: Buffer;
mimeType: "image/jpeg" | "image/png" | "image/webp";
pixelHeight: number;
pixelWidth: number;
}
export type GenerationAdapterResult =
| { outputs: readonly NormalizedGenerationOutput[]; status: "completed" }
| {
balanceSignal?: { gatewayAccountRef: string; impactScope: "model" | "account" | "unknown" };
category: GenerationErrorCategory;
sourceCategory: string;
status: "failed";
};
export interface GenerationAdapter {
start(request: GenerationAdapterRequest): Promise<GenerationAdapterResult>;
}
type MockResult = GenerationAdapterResult & { unsafeRaw?: string };
export class MockGenerationAdapter implements GenerationAdapter {
readonly calls: Array<{ generationId: string; modelId: string }> = [];
private readonly result: MockResult;
constructor(result: MockResult) {
this.result = result;
}
async start(request: GenerationAdapterRequest): Promise<GenerationAdapterResult> {
this.calls.push({ generationId: request.generationId, modelId: request.modelId });
if (this.result.status === "completed") {
return { outputs: this.result.outputs.map((output) => ({ ...output, bytes: Buffer.from(output.bytes) })), status: "completed" };
}
return {
...(this.result.balanceSignal ? { balanceSignal: { ...this.result.balanceSignal } } : {}),
category: this.result.category,
sourceCategory: this.result.sourceCategory,
status: "failed",
};
}
}