Skip to content

Commit 77dd020

Browse files
committed
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
1 parent 922bf8e commit 77dd020

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

index.d.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module "replicate" {
2-
type Status = "starting" | "processing" | "succeeded" | "failed" | "canceled" | "aborted";
2+
type Status = "starting" | "processing" | "succeeded" | "failed" | "canceled";
33
type Visibility = "public" | "private";
44
type WebhookEventType = "start" | "output" | "logs" | "completed";
55

@@ -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,25 @@ 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?: {
103-
predict_time?: number;
107+
total_time?: number;
104108
};
105109
webhook?: string;
106110
webhook_events_filter?: WebhookEventType[];
@@ -111,10 +115,37 @@ declare module "replicate" {
111115
get: string;
112116
cancel: string;
113117
stream?: string;
118+
web?: string;
114119
};
115120
}
116121

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

119150
export type FileEncodingStrategy = "default" | "upload" | "data-uri";
120151

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)