Skip to content

Commit f1aecc6

Browse files
committed
feat: add create actor input
1 parent 2f4b47c commit f1aecc6

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

packages/actor-core/src/actor/config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ export const ActorConfigSchema = z
7474
},
7575
);
7676

77+
export interface OnCreateOptions {
78+
input?: unknown;
79+
}
80+
81+
export interface CreateStateOptions {
82+
input?: unknown;
83+
}
84+
7785
export interface OnConnectOptions<CP> {
7886
/**
7987
* The request object associated with the connection.
@@ -92,6 +100,7 @@ type CreateState<S, CP, CS, V> =
92100
| {
93101
createState: (
94102
c: ActorContext<undefined, undefined, undefined, undefined>,
103+
opts: CreateStateOptions,
95104
) => S | Promise<S>;
96105
}
97106
| Record<never, never>;
@@ -149,7 +158,10 @@ interface BaseActorConfig<S, CP, CS, V, R extends Actions<S, CP, CS, V>> {
149158
* Use this hook to initialize your actor's state.
150159
* This is called before any other lifecycle hooks.
151160
*/
152-
onCreate?: (c: ActorContext<S, CP, CS, V>) => void | Promise<void>;
161+
onCreate?: (
162+
c: ActorContext<S, CP, CS, V>,
163+
opts: OnCreateOptions,
164+
) => void | Promise<void>;
153165

154166
/**
155167
* Called when the actor is started and ready to receive connections and action.

packages/actor-core/src/actor/instance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ export class ActorInstance<S, CP, CS, V> {
499499
logger().info("actor creating");
500500

501501
if (this.#config.onCreate) {
502-
await this.#config.onCreate(this.actorContext);
502+
await this.#config.onCreate(this.actorContext, { input });
503503
}
504504

505505
// Initialize actor state
@@ -518,6 +518,7 @@ export class ActorInstance<S, CP, CS, V> {
518518
undefined,
519519
undefined
520520
>,
521+
{ input }
521522
);
522523
} else if ("state" in this.#config) {
523524
stateData = structuredClone(this.#config.state);

packages/actor-core/src/manager/driver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface CreateInput<E extends Env = any> {
3333
name: string;
3434
key: ActorKey;
3535
region?: string;
36+
input: unknown;
3637
}
3738

3839
export interface ActorOutput {

0 commit comments

Comments
 (0)