Skip to content

Commit 0702cc5

Browse files
chengzeyiclaude
andcommitted
Results carry the API's optional details object
run() and runNoThrow() add `details` (structured information about the outputs, e.g. what each file is) when the model returns it. A result without it is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent f0c7670 commit 0702cc5

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

‎src/api/client.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export interface RunDetail {
237237
*/
238238
export interface RunNoThrowResult {
239239
outputs: any[] | null; // Model outputs (null if failed)
240+
details?: Record<string, any>; // Structured information about the outputs, when the model returns it
240241
detail: RunDetail; // Detailed information including taskId
241242
}
242243

@@ -535,6 +536,18 @@ export class Client {
535536
throw lastError!;
536537
}
537538

539+
/**
540+
* Build the result of a completed prediction: "outputs", plus the optional
541+
* "details" object when the API returned one.
542+
*/
543+
private _completedResult(data: Record<string, any>): { outputs: any[]; details?: Record<string, any> } {
544+
const result: { outputs: any[]; details?: Record<string, any> } = { outputs: data.outputs || [] };
545+
if (data.details != null) {
546+
result.details = data.details;
547+
}
548+
return result;
549+
}
550+
538551
/**
539552
* Wait for prediction to complete.
540553
*
@@ -573,7 +586,7 @@ export class Client {
573586
const status = data.status;
574587

575588
if (status === 'completed') {
576-
return { outputs: data.outputs || [] };
589+
return this._completedResult(data);
577590
}
578591

579592
if (TERMINAL_FAILURE_STATUSES.has(status)) {
@@ -675,7 +688,7 @@ export class Client {
675688
if (status !== 'completed') {
676689
throw this._syncModeError(data, model);
677690
}
678-
return { outputs: data.outputs || [] };
691+
return this._completedResult(data);
679692
}
680693

681694
if (requestId) {
@@ -782,7 +795,7 @@ export class Client {
782795
}
783796

784797
return {
785-
outputs: data.outputs || [],
798+
...this._completedResult(data),
786799
detail: {
787800
taskId,
788801
status: 'completed',
@@ -796,6 +809,7 @@ export class Client {
796809
const result = await this._wait(requestId, timeout, pollInterval);
797810
return {
798811
outputs: result.outputs,
812+
...(result.details != null ? { details: result.details } : {}),
799813
detail: {
800814
taskId: requestId,
801815
status: 'completed',

‎tests/test_api.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,43 @@ describe('Client', () => {
317317
expect(global.fetch).toHaveBeenCalledTimes(1);
318318
});
319319

320+
test('run and runNoThrow carry object outputs and details', async () => {
321+
const data = {
322+
id: 'req-123',
323+
status: 'completed',
324+
outputs: [{ url: 'https://example.com/a.mp4', duration: 5 }],
325+
details: { clips: [{ start: 0, end: 5 }] }
326+
};
327+
(global.fetch as jest.Mock).mockResolvedValue({
328+
ok: true,
329+
status: 200,
330+
json: async () => ({ data }),
331+
});
332+
const client = new Client('test-key');
333+
334+
for (const enableSyncMode of [false, true]) {
335+
const result = await client.run('wavespeed-ai/z-image/turbo', { prompt: 'test' }, { enableSyncMode });
336+
expect(result).toEqual({ outputs: data.outputs, details: data.details });
337+
338+
const noThrow = await client.runNoThrow('wavespeed-ai/z-image/turbo', { prompt: 'test' }, { enableSyncMode });
339+
expect(noThrow.outputs).toEqual(data.outputs);
340+
expect(noThrow.details).toEqual(data.details);
341+
}
342+
});
343+
344+
test('run result has no details key when the API returns none', async () => {
345+
(global.fetch as jest.Mock).mockResolvedValue({
346+
ok: true,
347+
status: 200,
348+
json: async () => ({ data: { status: 'completed', outputs: ['https://example.com/out.png'] } }),
349+
});
350+
351+
const client = new Client('test-key');
352+
const result = await client.run('wavespeed-ai/z-image/turbo', { prompt: 'test' }, { enableSyncMode: true });
353+
354+
expect(result).toEqual({ outputs: ['https://example.com/out.png'] });
355+
});
356+
320357
test('run sync mode failure', async () => {
321358
const mockResponse = {
322359
ok: true,

0 commit comments

Comments
 (0)