Skip to content

Commit c0334fa

Browse files
committed
chore(rivetkit): remove deprecated conn tokens & sse support
1 parent 03ec45c commit c0334fa

File tree

52 files changed

+436
-1227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+436
-1227
lines changed

examples/cursors-raw-websocket/src/frontend/App.tsx

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rivetkit-openapi/openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"openapi": "3.0.0",
33
"info": {
4-
"version": "2.0.22",
4+
"version": "2.0.24-rc.1",
55
"title": "RivetKit API"
66
},
77
"components": {

rivetkit-rust/packages/client/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub const HEADER_RIVET_ACTOR: &str = "x-rivet-actor";
2121
pub const HEADER_RIVET_TOKEN: &str = "x-rivet-token";
2222

2323
// Paths
24-
pub const PATH_CONNECT_WEBSOCKET: &str = "/connect/websocket";
24+
pub const PATH_CONNECT_WEBSOCKET: &str = "/connect";
2525

2626
// WebSocket protocol prefixes
2727
pub const WS_PROTOCOL_STANDARD: &str = "rivet";
@@ -63,4 +63,4 @@ impl ToString for EncodingKind {
6363

6464

6565
// Max size of each entry is 128 bytes
66-
pub type ActorKey = Vec<String>;
66+
pub type ActorKey = Vec<String>;

rivetkit-typescript/packages/cloudflare-workers/src/manager-driver.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import {
1010
type ManagerDisplayInformation,
1111
type ManagerDriver,
1212
WS_PROTOCOL_ACTOR,
13-
WS_PROTOCOL_CONN_ID,
1413
WS_PROTOCOL_CONN_PARAMS,
15-
WS_PROTOCOL_CONN_TOKEN,
1614
WS_PROTOCOL_ENCODING,
1715
WS_PROTOCOL_STANDARD,
1816
WS_PROTOCOL_TARGET,
@@ -76,8 +74,6 @@ export class CloudflareActorsManagerDriver implements ManagerDriver {
7674
actorId: string,
7775
encoding: Encoding,
7876
params: unknown,
79-
connId?: string,
80-
connToken?: string,
8177
): Promise<UniversalWebSocket> {
8278
const env = getCloudflareAmbientEnv();
8379

@@ -101,12 +97,6 @@ export class CloudflareActorsManagerDriver implements ManagerDriver {
10197
`${WS_PROTOCOL_CONN_PARAMS}${encodeURIComponent(JSON.stringify(params))}`,
10298
);
10399
}
104-
if (connId) {
105-
protocols.push(`${WS_PROTOCOL_CONN_ID}${connId}`);
106-
}
107-
if (connToken) {
108-
protocols.push(`${WS_PROTOCOL_CONN_TOKEN}${connToken}`);
109-
}
110100

111101
const headers: Record<string, string> = {
112102
Upgrade: "websocket",

rivetkit-typescript/packages/rivetkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
],
154154
"scripts": {
155155
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts",
156-
"build:schema": "./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v2.bare -o dist/schemas/actor-persist/v2.ts",
156+
"build:schema": "./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/client-protocol/v2.bare -o dist/schemas/client-protocol/v2.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v2.bare -o dist/schemas/actor-persist/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v3.bare -o dist/schemas/actor-persist/v3.ts",
157157
"check-types": "tsc --noEmit",
158158
"test": "vitest run",
159159
"test:watch": "vitest",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# MARK: Connection
2+
# Connection associated with hibernatable WebSocket that should persist across lifecycles.
3+
type PersistedHibernatableConn struct {
4+
# Connection ID generated by RivetKit
5+
id: str
6+
parameters: data
7+
state: data
8+
9+
# Request ID of the hibernatable WebSocket
10+
hibernatableRequestId: data
11+
# Last seen message from this WebSocket
12+
lastSeenTimestamp: i64
13+
# Last seem message index for this WebSocket
14+
msgIndex: i64
15+
}
16+
17+
# MARK: Schedule Event
18+
type PersistedScheduleEvent struct {
19+
eventId: str
20+
timestamp: i64
21+
action: str
22+
args: optional<data>
23+
}
24+
25+
# MARK: Actor
26+
type PersistedActor struct {
27+
# Input data passed to the actor on initialization
28+
input: optional<data>
29+
hasInitialized: bool
30+
state: data
31+
hibernatableConns: list<PersistedHibernatableConn>
32+
scheduledEvents: list<PersistedScheduleEvent>
33+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# MARK: Message To Client
2+
type Init struct {
3+
actorId: str
4+
connectionId: str
5+
}
6+
7+
type Error struct {
8+
group: str
9+
code: str
10+
message: str
11+
metadata: optional<data>
12+
actionId: optional<uint>
13+
}
14+
15+
type ActionResponse struct {
16+
id: uint
17+
output: data
18+
}
19+
20+
type Event struct {
21+
name: str
22+
# CBOR array
23+
args: data
24+
}
25+
26+
type ToClientBody union {
27+
Init |
28+
Error |
29+
ActionResponse |
30+
Event
31+
}
32+
33+
type ToClient struct {
34+
body: ToClientBody
35+
}
36+
37+
# MARK: Message To Server
38+
type ActionRequest struct {
39+
id: uint
40+
name: str
41+
# CBOR array
42+
args: data
43+
}
44+
45+
type SubscriptionRequest struct {
46+
eventName: str
47+
subscribe: bool
48+
}
49+
50+
type ToServerBody union {
51+
ActionRequest |
52+
SubscriptionRequest
53+
}
54+
55+
type ToServer struct {
56+
body: ToServerBody
57+
}
58+
59+
# MARK: HTTP Action
60+
type HttpActionRequest struct {
61+
# CBOR array
62+
args: data
63+
}
64+
65+
type HttpActionResponse struct {
66+
output: data
67+
}
68+
69+
# MARK: HTTP Error
70+
type HttpResponseError struct {
71+
group: str
72+
code: str
73+
message: str
74+
metadata: optional<data>
75+
}
76+
77+
# MARK: HTTP Resolve
78+
type HttpResolveRequest void
79+
80+
type HttpResolveResponse struct {
81+
actorId: str
82+
}

rivetkit-typescript/packages/rivetkit/src/actor/conn-drivers.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { SSEStreamingApi } from "hono/streaming";
21
import type { WSContext } from "hono/ws";
32
import type { WebSocket } from "ws";
43
import type { AnyConn } from "@/actor/conn";
@@ -11,7 +10,6 @@ import { assertUnreachable, type promiseWithResolvers } from "@/utils";
1110

1211
export enum ConnDriverKind {
1312
WEBSOCKET = 0,
14-
SSE = 1,
1513
HTTP = 2,
1614
}
1715

@@ -29,16 +27,10 @@ export interface ConnDriverWebSocketState {
2927
closePromise: ReturnType<typeof promiseWithResolvers<void>>;
3028
}
3129

32-
export interface ConnDriverSseState {
33-
encoding: Encoding;
34-
stream: SSEStreamingApi;
35-
}
36-
3730
export type ConnDriverHttpState = Record<never, never>;
3831

3932
export type ConnDriverState =
4033
| { [ConnDriverKind.WEBSOCKET]: ConnDriverWebSocketState }
41-
| { [ConnDriverKind.SSE]: ConnDriverSseState }
4234
| { [ConnDriverKind.HTTP]: ConnDriverHttpState };
4335

4436
export interface ConnDriver<State> {
@@ -152,41 +144,6 @@ const WEBSOCKET_DRIVER: ConnDriver<ConnDriverWebSocketState> = {
152144
},
153145
};
154146

155-
// MARK: SSE
156-
const SSE_DRIVER: ConnDriver<ConnDriverSseState> = {
157-
sendMessage: (
158-
_actor: AnyActorInstance,
159-
_conn: AnyConn,
160-
state: ConnDriverSseState,
161-
message: CachedSerializer<protocol.ToClient>,
162-
) => {
163-
state.stream.writeSSE({
164-
data: encodeDataToString(message.serialize(state.encoding)),
165-
});
166-
},
167-
168-
disconnect: async (
169-
_actor: AnyActorInstance,
170-
_conn: AnyConn,
171-
state: ConnDriverSseState,
172-
_reason?: string,
173-
) => {
174-
state.stream.close();
175-
},
176-
177-
getConnectionReadyState: (
178-
_actor: AnyActorInstance,
179-
_conn: AnyConn,
180-
state: ConnDriverSseState,
181-
): ConnReadyState | undefined => {
182-
if (state.stream.aborted || state.stream.closed) {
183-
return ConnReadyState.CLOSED;
184-
}
185-
186-
return ConnReadyState.OPEN;
187-
},
188-
};
189-
190147
// MARK: HTTP
191148
const HTTP_DRIVER: ConnDriver<ConnDriverHttpState> = {
192149
getConnectionReadyState(_actor, _conn) {
@@ -202,15 +159,13 @@ const HTTP_DRIVER: ConnDriver<ConnDriverHttpState> = {
202159
/** List of all connection drivers. */
203160
export const CONN_DRIVERS: Record<ConnDriverKind, ConnDriver<unknown>> = {
204161
[ConnDriverKind.WEBSOCKET]: WEBSOCKET_DRIVER,
205-
[ConnDriverKind.SSE]: SSE_DRIVER,
206162
[ConnDriverKind.HTTP]: HTTP_DRIVER,
207163
};
208164

209165
export function getConnDriverKindFromState(
210166
state: ConnDriverState,
211167
): ConnDriverKind {
212168
if (ConnDriverKind.WEBSOCKET in state) return ConnDriverKind.WEBSOCKET;
213-
else if (ConnDriverKind.SSE in state) return ConnDriverKind.SSE;
214169
else if (ConnDriverKind.HTTP in state) return ConnDriverKind.HTTP;
215170
else assertUnreachable(state);
216171
}

rivetkit-typescript/packages/rivetkit/src/actor/conn-socket.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ConnDriverState } from "./conn-drivers";
22

33
export interface ConnSocket {
4+
/** This is the request ID provided by the given framework. If not provided this is a random UUID. */
45
requestId: string;
56
requestIdBuf?: ArrayBuffer;
67
hibernatable: boolean;

rivetkit-typescript/packages/rivetkit/src/actor/conn.ts

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import * as cbor from "cbor-x";
2-
import invariant from "invariant";
3-
import { PersistedHibernatableWebSocket } from "@/schemas/actor-persist/mod";
42
import type * as protocol from "@/schemas/client-protocol/mod";
53
import { TO_CLIENT_VERSIONED } from "@/schemas/client-protocol/versioned";
64
import { arrayBuffersEqual, bufferToArrayBuffer } from "@/utils";
75
import {
86
CONN_DRIVERS,
9-
ConnDriverKind,
107
type ConnDriverState,
11-
ConnReadyState,
128
getConnDriverKindFromState,
139
} from "./conn-drivers";
1410
import type { ConnSocket } from "./conn-socket";
@@ -17,15 +13,6 @@ import * as errors from "./errors";
1713
import { type ActorInstance, PERSIST_SYMBOL } from "./instance";
1814
import type { PersistedConn } from "./persisted";
1915
import { CachedSerializer } from "./protocol/serde";
20-
import { generateSecureToken } from "./utils";
21-
22-
export function generateConnId(): string {
23-
return crypto.randomUUID();
24-
}
25-
26-
export function generateConnToken(): string {
27-
return generateSecureToken(32);
28-
}
2916

3017
export function generateConnRequestId(): string {
3118
return crypto.randomUUID();
@@ -35,8 +22,6 @@ export type ConnId = string;
3522

3623
export type AnyConn = Conn<any, any, any, any, any, any>;
3724

38-
export type ConnectionStatus = "connected" | "reconnecting";
39-
4025
/**
4126
* Represents a client connection to a actor.
4227
*
@@ -53,7 +38,11 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
5338
/**
5439
* The proxied state that notifies of changes automatically.
5540
*
56-
* Any data that should be stored indefinitely should be held within this object.
41+
* Any data that should be stored indefinitely should be held within this
42+
* object.
43+
*
44+
* This will only be persisted if using hibernatable WebSockets. If not,
45+
* this is just used to hole state.
5746
*/
5847
__persist: PersistedConn<CP, CS>;
5948

@@ -68,15 +57,6 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
6857
*/
6958
__socket?: ConnSocket;
7059

71-
get __status(): ConnectionStatus {
72-
// TODO: isHibernatible might be true while the actual hibernatable websocket has disconnected
73-
if (this.__socket || this.isHibernatable) {
74-
return "connected";
75-
} else {
76-
return "reconnecting";
77-
}
78-
}
79-
8060
public get params(): CP {
8161
return this.__persist.params;
8262
}
@@ -113,20 +93,6 @@ export class Conn<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
11393
return this.__persist.connId;
11494
}
11595

116-
/**
117-
* Token used to authenticate this request.
118-
*/
119-
public get _token(): string {
120-
return this.__persist.token;
121-
}
122-
123-
/**
124-
* Status of the connection.
125-
*/
126-
public get status(): ConnectionStatus {
127-
return this.__status;
128-
}
129-
13096
/**
13197
* @experimental
13298
*

0 commit comments

Comments
 (0)