Skip to content

Commit 6127de0

Browse files
NathanFlurryMasterPtato
authored andcommitted
fix(rivetkit): expose client actor metadata
1 parent a499917 commit 6127de0

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Design constraints, invariants, and reference commands for the Rivet monorepo. F
2424

2525
- Avoid raw `f64` fields in vbare protocol schemas that use hashable maps; generated Rust derives `Eq`/`Hash`, so encode floats as fixed bytes or an ordered wrapper.
2626
- Version converters must manually map fields between versions; never use serialize-deserialize round trips such as `transcode_version` or `serde_bare::to_vec` plus `from_slice`.
27+
- RivetKit client/server protocol compatibility assumes the server/runtime is newer than the client; clients send their latest request protocol version, and servers handle older-client compatibility and negotiation.
2728

2829
When talking about "Rivet Actors" make sure to capitalize "Rivet Actor" as a proper noun and lowercase "actor" as a generic noun.
2930

rivetkit-asyncapi/asyncapi.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,33 @@
123123
"type": "null"
124124
}
125125
]
126+
},
127+
"actor": {
128+
"type": "object",
129+
"properties": {
130+
"actorId": {
131+
"type": "string"
132+
},
133+
"generation": {
134+
"anyOf": [
135+
{
136+
"type": "number"
137+
},
138+
{
139+
"type": "integer",
140+
"format": "int64"
141+
}
142+
]
143+
},
144+
"key": {
145+
"type": "string"
146+
}
147+
},
148+
"required": [
149+
"actorId",
150+
"generation"
151+
],
152+
"additionalProperties": false
126153
}
127154
},
128155
"required": [
@@ -421,6 +448,33 @@
421448
"type": "null"
422449
}
423450
]
451+
},
452+
"actor": {
453+
"type": "object",
454+
"properties": {
455+
"actorId": {
456+
"type": "string"
457+
},
458+
"generation": {
459+
"anyOf": [
460+
{
461+
"type": "number"
462+
},
463+
{
464+
"type": "integer",
465+
"format": "int64"
466+
}
467+
]
468+
},
469+
"key": {
470+
"type": "string"
471+
}
472+
},
473+
"required": [
474+
"actorId",
475+
"generation"
476+
],
477+
"additionalProperties": false
424478
}
425479
},
426480
"required": [

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ export class ActorConnRaw {
216216
this.#encoding = encoding;
217217
this.#actorResolutionState = actorResolutionState;
218218
this.#gatewayOptions = resolveActorGatewayOptions(gatewayOptions);
219+
if ("getForId" in actorResolutionState) {
220+
this.#actorId = actorResolutionState.getForId.actorId;
221+
}
219222
this.#readyPromise = promiseWithResolvers((reason) =>
220223
logger().warn({
221224
msg: "unhandled ready promise rejection",

rivetkit-typescript/packages/rivetkit/tests/driver/actor-conn.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ describeDriverMatrix("Actor Conn", (driverTestConfig) => {
100100
await connection.dispose();
101101
});
102102

103+
test("should expose actorId after connection init", async (c) => {
104+
const { client } = await setupDriverTest(c, driverTestConfig);
105+
106+
const handle = client.counter.getOrCreate([
107+
"test-conn-actor-id",
108+
]);
109+
const connection = handle.connect();
110+
111+
await connection.ready;
112+
expect(connection.actorId).toBe(await handle.resolve());
113+
114+
await connection.dispose();
115+
});
116+
103117
test("should connect using (await create()).connect()", async (c) => {
104118
const { client } = await setupDriverTest(c, driverTestConfig);
105119

0 commit comments

Comments
 (0)