Skip to content

Commit 6124a0e

Browse files
authored
feat: update types to match OpenAPI schema (#363)
* feat: update types to match OpenAPI schema This PR updates TypeScript types to match the OpenAPI schema from https://api.replicate.com/openapi.json Changes: - Account: add avatar_url field - Status: remove "aborted" status (not in OpenAPI schema) - FileObject: replace name, etag, checksum with checksums object - Prediction: add data_removed, deadline, deployment fields; change version to support "hidden"; update metrics to use total_time; add web URL - Training: convert from type alias to full interface with proper output structure - ModelVersion: make cog_version and openapi_schema nullable * fix: keep predict_time in Prediction metrics for backward compatibility * feat: add "aborted" status to Status type Per the OpenAPI schema, both predictions and trainings can have an "aborted" status, which indicates the task was terminated before it started running (e.g., when a deadline is reached before execution begins). * fix: add web URL to Training.urls Per the OpenAPI schema, Training objects include a web URL in their urls object, matching the Prediction interface.
1 parent 922bf8e commit 6124a0e

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

index.d.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ declare module "replicate" {
1919
username: string;
2020
name: string;
2121
github_url?: string;
22+
avatar_url?: string;
2223
}
2324

2425
export interface Collection {
@@ -48,11 +49,11 @@ declare module "replicate" {
4849

4950
export interface FileObject {
5051
id: string;
51-
name: string;
5252
content_type: string;
5353
size: number;
54-
etag: string;
55-
checksum: string;
54+
checksums: {
55+
sha256: string;
56+
};
5657
metadata: Record<string, unknown>;
5758
created_at: string;
5859
expires_at: string | null;
@@ -85,22 +86,26 @@ declare module "replicate" {
8586
export interface ModelVersion {
8687
id: string;
8788
created_at: string;
88-
cog_version: string;
89-
openapi_schema: object;
89+
cog_version: string | null;
90+
openapi_schema: object | null;
9091
}
9192

9293
export interface Prediction {
9394
id: string;
9495
status: Status;
9596
model: string;
96-
version: string;
97+
version: string | "hidden";
9798
input: object;
9899
output?: any; // TODO: this should be `unknown`
99100
source: "api" | "web";
100101
error?: unknown;
101102
logs?: string;
103+
data_removed: boolean;
104+
deadline?: string;
105+
deployment?: string;
102106
metrics?: {
103107
predict_time?: number;
108+
total_time?: number;
104109
};
105110
webhook?: string;
106111
webhook_events_filter?: WebhookEventType[];
@@ -111,10 +116,38 @@ declare module "replicate" {
111116
get: string;
112117
cancel: string;
113118
stream?: string;
119+
web?: string;
114120
};
115121
}
116122

117-
export type Training = Prediction;
123+
export interface Training {
124+
id: string;
125+
status: Status;
126+
model: string;
127+
version: string;
128+
input: object;
129+
output?: {
130+
version?: string;
131+
weights?: string;
132+
};
133+
source: "api" | "web";
134+
error?: unknown;
135+
logs?: string;
136+
metrics?: {
137+
predict_time?: number;
138+
total_time?: number;
139+
};
140+
webhook?: string;
141+
webhook_events_filter?: WebhookEventType[];
142+
created_at: string;
143+
started_at?: string;
144+
completed_at?: string;
145+
urls: {
146+
get: string;
147+
cancel: string;
148+
web?: string;
149+
};
150+
}
118151

119152
export type FileEncodingStrategy = "default" | "upload" | "data-uri";
120153

index.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Replicate, {
44
FileOutput,
55
Model,
66
Prediction,
7+
Training,
78
validateWebhook,
89
parseProgressFromLogs,
910
} from "replicate";
@@ -906,7 +907,7 @@ describe("Replicate client", () => {
906907
next: null,
907908
});
908909

909-
const results: Prediction[] = [];
910+
const results: Training[] = [];
910911
for await (const batch of client.paginate(client.trainings.list)) {
911912
results.push(...batch);
912913
}
@@ -1176,11 +1177,11 @@ describe("Replicate client", () => {
11761177
.post("/files")
11771178
.reply(200, {
11781179
id: "123",
1179-
name: "test-file",
11801180
content_type: "application/octet-stream",
11811181
size: 1024,
1182-
etag: "abc123",
1183-
checksum: "sha256:1234567890abcdef",
1182+
checksums: {
1183+
sha256: "1234567890abcdef",
1184+
},
11841185
metadata: {},
11851186
created_at: "2023-01-01T00:00:00Z",
11861187
expires_at: null,
@@ -1190,7 +1191,6 @@ describe("Replicate client", () => {
11901191
});
11911192
const file = await client.files.create(testCase.value);
11921193
expect(file.id).toBe("123");
1193-
expect(file.name).toBe("test-file");
11941194
}
11951195
});
11961196
});
@@ -1201,11 +1201,11 @@ describe("Replicate client", () => {
12011201
.get("/files/123")
12021202
.reply(200, {
12031203
id: "123",
1204-
name: "test-file",
12051204
content_type: "application/octet-stream",
12061205
size: 1024,
1207-
etag: "abc123",
1208-
checksum: "sha256:1234567890abcdef",
1206+
checksums: {
1207+
sha256: "1234567890abcdef",
1208+
},
12091209
metadata: {},
12101210
created_at: "2023-01-01T00:00:00Z",
12111211
expires_at: null,
@@ -1216,7 +1216,6 @@ describe("Replicate client", () => {
12161216

12171217
const file = await client.files.get("123");
12181218
expect(file.id).toBe("123");
1219-
expect(file.name).toBe("test-file");
12201219
});
12211220
});
12221221

@@ -1230,11 +1229,11 @@ describe("Replicate client", () => {
12301229
results: [
12311230
{
12321231
id: "123",
1233-
name: "test-file",
12341232
content_type: "application/octet-stream",
12351233
size: 1024,
1236-
etag: "abc123",
1237-
checksum: "sha256:1234567890abcdef",
1234+
checksums: {
1235+
sha256: "1234567890abcdef",
1236+
},
12381237
metadata: {},
12391238
created_at: "2023-01-01T00:00:00Z",
12401239
expires_at: null,

0 commit comments

Comments
 (0)