Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit ecc0c9d

Browse files
committed
chore(core): update api schema to match new engine schema
1 parent 9ea5720 commit ecc0c9d

File tree

19 files changed

+323
-358
lines changed

19 files changed

+323
-358
lines changed

clients/openapi/openapi.json

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"parameters": {}
1010
},
1111
"paths": {
12-
"/actors/by-id": {
12+
"/actors": {
1313
"get": {
1414
"parameters": [
1515
{
@@ -37,11 +37,60 @@
3737
"schema": {
3838
"type": "object",
3939
"properties": {
40-
"actor_id": {
41-
"type": "string",
42-
"nullable": true
40+
"actors": {
41+
"type": "array",
42+
"items": {
43+
"type": "object",
44+
"properties": {
45+
"actor_id": {
46+
"type": "string"
47+
},
48+
"name": {
49+
"type": "string"
50+
},
51+
"key": {
52+
"type": "string"
53+
},
54+
"namespace_id": {
55+
"type": "string"
56+
},
57+
"runner_name_selector": {
58+
"type": "string"
59+
},
60+
"create_ts": {
61+
"type": "number"
62+
},
63+
"connectable_ts": {
64+
"type": "number",
65+
"nullable": true
66+
},
67+
"destroy_ts": {
68+
"type": "number",
69+
"nullable": true
70+
},
71+
"sleep_ts": {
72+
"type": "number",
73+
"nullable": true
74+
},
75+
"start_ts": {
76+
"type": "number",
77+
"nullable": true
78+
}
79+
},
80+
"required": [
81+
"actor_id",
82+
"name",
83+
"key",
84+
"namespace_id",
85+
"runner_name_selector",
86+
"create_ts"
87+
]
88+
}
4389
}
44-
}
90+
},
91+
"required": [
92+
"actors"
93+
]
4594
}
4695
}
4796
}
@@ -91,50 +140,6 @@
91140
}
92141
}
93142
},
94-
"responses": {
95-
"200": {
96-
"description": "Success",
97-
"content": {
98-
"application/json": {
99-
"schema": {
100-
"type": "object",
101-
"properties": {
102-
"actor_id": {
103-
"type": "string"
104-
},
105-
"created": {
106-
"type": "boolean"
107-
}
108-
},
109-
"required": [
110-
"actor_id",
111-
"created"
112-
]
113-
}
114-
}
115-
}
116-
},
117-
"400": {
118-
"description": "User error"
119-
},
120-
"500": {
121-
"description": "Internal error"
122-
}
123-
}
124-
}
125-
},
126-
"/actors/{actor_id}": {
127-
"get": {
128-
"parameters": [
129-
{
130-
"schema": {
131-
"type": "string"
132-
},
133-
"required": true,
134-
"name": "actor_id",
135-
"in": "path"
136-
}
137-
],
138143
"responses": {
139144
"200": {
140145
"description": "Success",
@@ -189,10 +194,14 @@
189194
"runner_name_selector",
190195
"create_ts"
191196
]
197+
},
198+
"created": {
199+
"type": "boolean"
192200
}
193201
},
194202
"required": [
195-
"actor"
203+
"actor",
204+
"created"
196205
]
197206
}
198207
}
@@ -205,9 +214,7 @@
205214
"description": "Internal error"
206215
}
207216
}
208-
}
209-
},
210-
"/actors": {
217+
},
211218
"post": {
212219
"requestBody": {
213220
"content": {

packages/rivetkit/fixtures/driver-test-suite/conn-state.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type ConnState = {
55
role: string;
66
counter: number;
77
createdAt: number;
8+
noCount: boolean;
89
};
910

1011
export const connStateActor = actor({
@@ -16,13 +17,14 @@ export const connStateActor = actor({
1617
createConnState: (
1718
c,
1819
opts,
19-
params: { username?: string; role?: string },
20+
params: { username?: string; role?: string; noCount?: boolean },
2021
): ConnState => {
2122
return {
2223
username: params?.username || "anonymous",
2324
role: params?.role || "user",
2425
counter: 0,
2526
createdAt: Date.now(),
27+
noCount: params?.noCount ?? false,
2628
};
2729
},
2830
// Lifecycle hook when a connection is established
@@ -36,10 +38,12 @@ export const connStateActor = actor({
3638
},
3739
// Lifecycle hook when a connection is closed
3840
onDisconnect: (c, conn) => {
39-
c.state.disconnectionCount += 1;
40-
c.broadcast("userDisconnected", {
41-
id: conn.id,
42-
});
41+
if (!conn.state?.noCount) {
42+
c.state.disconnectionCount += 1;
43+
c.broadcast("userDisconnected", {
44+
id: conn.id,
45+
});
46+
}
4347
},
4448
actions: {
4549
// Action to increment the connection's counter
@@ -60,7 +64,11 @@ export const connStateActor = actor({
6064

6165
// Check all active connections
6266
getConnectionIds: (c) => {
63-
return c.conns.keys().toArray();
67+
return c.conns
68+
.entries()
69+
.filter((c) => !c[1].state?.noCount)
70+
.map((x) => x[0])
71+
.toArray();
6472
},
6573

6674
// Get disconnection count

packages/rivetkit/scripts/dump-openapi.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function main() {
3737
registryConfig,
3838
driverConfig,
3939
managerDriver,
40-
true,
4140
);
4241

4342
const openApiDoc = openapi.getOpenAPIDocument({

packages/rivetkit/src/driver-test-suite/mod.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ export async function createTestRuntime(
197197
registry.config,
198198
config,
199199
managerDriver,
200-
false,
201200
);
202201

203202
// Inject WebSocket

packages/rivetkit/src/driver-test-suite/tests/actor-conn-state.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,31 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) {
145145
});
146146

147147
describe("Connection Lifecycle", () => {
148-
test("should track connection and disconnection events", async (c) => {
148+
test.skipIf(
149+
driverTestConfig.transport === "sse" &&
150+
driverTestConfig.clientType === "inline",
151+
)("should track connection and disconnection events", async (c) => {
149152
const { client } = await setupDriverTest(c, driverTestConfig);
150153

154+
const debugHandle = client.connStateActor.getOrCreate(undefined, {
155+
params: { noCount: true },
156+
});
157+
151158
// Create a connection
152-
const handle = client.connStateActor.getOrCreate();
153-
const conn = handle.connect();
159+
const conn = client.connStateActor.getOrCreate().connect();
154160

155161
// Get the connection state
156162
const connState = await conn.getConnectionState();
157163

158164
// Verify the connection is tracked
159165
await vi.waitFor(async () => {
160-
const connectionIds = await conn.getConnectionIds();
166+
const connectionIds = await debugHandle.getConnectionIds();
161167
expect(connectionIds).toContain(connState.id);
162168
});
163169

164170
// Initial disconnection count
165171
await vi.waitFor(async () => {
166-
const disconnects = await conn.getDisconnectionCount();
172+
const disconnects = await debugHandle.getDisconnectionCount();
167173
expect(disconnects).toBe(0);
168174
});
169175

@@ -173,7 +179,9 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) {
173179
// Validate conn count
174180
await vi.waitFor(
175181
async () => {
176-
const disconnects = await newConn.getDisconnectionCount();
182+
console.log("disconnects before");
183+
const disconnects = await debugHandle.getDisconnectionCount();
184+
console.log("disconnects", disconnects);
177185
expect(disconnects).toBe(1);
178186
},
179187
// SSE takes a long time to disconnect on CF Workers
@@ -184,12 +192,13 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) {
184192
);
185193

186194
// Create a new connection to check the disconnection count
187-
const newConn = handle.connect();
195+
const newConn = client.connStateActor.getOrCreate().connect();
188196

189197
// Verify the connection is tracked
190198
await vi.waitFor(async () => {
191-
const connectionIds = await conn.getConnectionIds();
192-
expect(connectionIds.length).toBe(2);
199+
const connectionIds = await debugHandle.getConnectionIds();
200+
console.log("conn ids", connectionIds);
201+
expect(connectionIds.length).toBe(1);
193202
});
194203

195204
// Clean up
@@ -198,7 +207,9 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) {
198207
// Verify disconnection was tracked
199208
await vi.waitFor(
200209
async () => {
201-
const disconnects = await newConn.getDisconnectionCount();
210+
console.log("A");
211+
const disconnects = await debugHandle.getDisconnectionCount();
212+
console.log(`B ${disconnects}`);
202213
expect(disconnects).toBe(2);
203214
},
204215
// SSE takes a long time to disconnect on CF Workers

packages/rivetkit/src/driver-test-suite/tests/actor-conn.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ export function runActorConnTests(driverTestConfig: DriverTestConfig) {
234234
});
235235

236236
describe("Lifecycle Hooks", () => {
237-
test("should trigger lifecycle hooks", async (c) => {
237+
test.skipIf(
238+
driverTestConfig.transport === "sse" &&
239+
driverTestConfig.clientType === "inline",
240+
)("should trigger lifecycle hooks", async (c) => {
238241
const { client } = await setupDriverTest(c, driverTestConfig);
239242

240243
// Create and connect
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { z } from "zod";
2+
import { RivetIdSchema } from "./common";
3+
4+
export const ActorSchema = z.object({
5+
actor_id: RivetIdSchema,
6+
name: z.string(),
7+
key: z.string(),
8+
namespace_id: RivetIdSchema,
9+
runner_name_selector: z.string(),
10+
create_ts: z.number(),
11+
connectable_ts: z.number().nullable().optional(),
12+
destroy_ts: z.number().nullable().optional(),
13+
sleep_ts: z.number().nullable().optional(),
14+
start_ts: z.number().nullable().optional(),
15+
});
16+
export type Actor = z.infer<typeof ActorSchema>;
17+
18+
// MARK: GET /actors
19+
export const ActorsListResponseSchema = z.object({
20+
actors: z.array(ActorSchema),
21+
});
22+
export type ActorsListResponse = z.infer<typeof ActorsListResponseSchema>;
23+
24+
// MARK: POST /actors
25+
export const ActorsCreateRequestSchema = z.object({
26+
name: z.string(),
27+
runner_name_selector: z.string(),
28+
crash_policy: z.string(),
29+
key: z.string().nullable().optional(),
30+
input: z.string().nullable().optional(),
31+
});
32+
export type ActorsCreateRequest = z.infer<typeof ActorsCreateRequestSchema>;
33+
34+
export const ActorsCreateResponseSchema = z.object({
35+
actor: ActorSchema,
36+
});
37+
export type ActorsCreateResponse = z.infer<typeof ActorsCreateResponseSchema>;
38+
39+
// MARK: PUT /actors
40+
export const ActorsGetOrCreateRequestSchema = z.object({
41+
name: z.string(),
42+
key: z.string(),
43+
runner_name_selector: z.string(),
44+
crash_policy: z.string(),
45+
input: z.string().nullable().optional(),
46+
});
47+
export type ActorsGetOrCreateRequest = z.infer<
48+
typeof ActorsGetOrCreateRequestSchema
49+
>;
50+
51+
export const ActorsGetOrCreateResponseSchema = z.object({
52+
actor: ActorSchema,
53+
created: z.boolean(),
54+
});
55+
export type ActorsGetOrCreateResponse = z.infer<
56+
typeof ActorsGetOrCreateResponseSchema
57+
>;
58+
59+
// MARK: DELETE /actors/{}
60+
export const ActorsDeleteResponseSchema = z.object({});
61+
export type ActorsDeleteResponse = z.infer<typeof ActorsDeleteResponseSchema>;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { z } from "zod";
2+
3+
export const RivetIdSchema = z.string();
4+
export type RivetId = z.infer<typeof RivetIdSchema>;

packages/rivetkit/src/manager-api/routes/actors-create.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/rivetkit/src/manager-api/routes/actors-delete.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)