@base44-preview/sdk 0.8.40-pr.212.55a476c → 0.8.40-pr.212.6649074
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actor.d.ts +3 -1
- package/dist/actor.js +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/modules/actors.d.ts +2 -2
- package/dist/modules/actors.js +43 -51
- package/dist/modules/actors.types.d.ts +23 -17
- package/package.json +1 -1
package/dist/actor.d.ts
CHANGED
|
@@ -77,7 +77,9 @@ export declare abstract class Actor<Incoming = unknown, Outgoing = unknown> {
|
|
|
77
77
|
protected get storage(): Storage;
|
|
78
78
|
/**
|
|
79
79
|
* Anonymous Base44 client scoped to this actor instance — no user or service
|
|
80
|
-
* auth, so entity access is RLS-gated (same as a logged-out visitor).
|
|
80
|
+
* auth, so entity access is RLS-gated (same as a logged-out visitor). Always
|
|
81
|
+
* operates on production data: an actor runs server-side with no per-connection
|
|
82
|
+
* identity, so a Test DB preview selected in the editor does not apply here.
|
|
81
83
|
* Example: `const rows = await this.client.entities.Score.list();`
|
|
82
84
|
*/
|
|
83
85
|
protected get client(): Base44Client;
|
package/dist/actor.js
CHANGED
|
@@ -62,7 +62,9 @@ export class Actor {
|
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Anonymous Base44 client scoped to this actor instance — no user or service
|
|
65
|
-
* auth, so entity access is RLS-gated (same as a logged-out visitor).
|
|
65
|
+
* auth, so entity access is RLS-gated (same as a logged-out visitor). Always
|
|
66
|
+
* operates on production data: an actor runs server-side with no per-connection
|
|
67
|
+
* identity, so a Test DB preview selected in the editor does not apply here.
|
|
66
68
|
* Example: `const rows = await this.client.entities.Score.list();`
|
|
67
69
|
*/
|
|
68
70
|
get client() {
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./mod
|
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
12
|
export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
|
|
13
13
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
14
|
-
export type { ActorsModule, ActorClient, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
14
|
+
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
15
15
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
16
16
|
export { Actor, type Conn } from "./actor.js";
|
|
17
17
|
export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
|
package/dist/modules/actors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ActorRef } from "./actors.types.js";
|
|
2
2
|
interface ActorsConfig {
|
|
3
3
|
appId: string;
|
|
4
4
|
/** Current user access token, if authenticated. Rides the WS query so the
|
|
@@ -19,7 +19,7 @@ interface ActorsConfig {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function resolveActorsHost(serverUrl: string, browserOrigin?: string): string;
|
|
21
21
|
export declare function createActorsModule(config: ActorsConfig): {
|
|
22
|
-
module: Record<string, (instanceId: string) =>
|
|
22
|
+
module: Record<string, (instanceId: string) => ActorRef>;
|
|
23
23
|
closeAll: () => void;
|
|
24
24
|
};
|
|
25
25
|
export {};
|
package/dist/modules/actors.js
CHANGED
|
@@ -3,43 +3,31 @@ import PartySocket from "partysocket";
|
|
|
3
3
|
// event, so ping periodically and force a reconnect if nothing returns in DEAD_MS.
|
|
4
4
|
const PING_MS = 1000;
|
|
5
5
|
const DEAD_MS = 3000;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* A live connection to an actor instance. Only obtainable from
|
|
8
|
+
* {@link ActorRef.connect}, so `subscribe`/`send` are always valid — the socket
|
|
9
|
+
* exists for this object's whole lifetime.
|
|
10
|
+
*/
|
|
11
|
+
class Connection {
|
|
12
|
+
constructor(actorName, instanceId, config, options, onClose) {
|
|
13
|
+
var _a;
|
|
11
14
|
this.onClose = onClose;
|
|
12
|
-
this.ws = null;
|
|
13
15
|
this.listeners = new Set();
|
|
14
16
|
this.heartbeat = null;
|
|
15
|
-
this.
|
|
16
|
-
}
|
|
17
|
-
get id() {
|
|
18
|
-
if (!this.connId) {
|
|
19
|
-
throw new Error(`${this.actorName}:${this.instanceId}: connect() before reading id`);
|
|
20
|
-
}
|
|
21
|
-
return this.connId;
|
|
22
|
-
}
|
|
23
|
-
connect(options) {
|
|
24
|
-
var _a;
|
|
25
|
-
if (this.ws)
|
|
26
|
-
return this;
|
|
27
|
-
// The client picks its own conn id; it becomes _pk → the actor's conn.id.
|
|
28
|
-
const connId = (_a = options === null || options === void 0 ? void 0 : options.id) !== null && _a !== void 0 ? _a : crypto.randomUUID();
|
|
29
|
-
this.connId = connId;
|
|
17
|
+
this.id = (_a = options === null || options === void 0 ? void 0 : options.id) !== null && _a !== void 0 ? _a : crypto.randomUUID();
|
|
30
18
|
const ws = new PartySocket({
|
|
31
|
-
host:
|
|
32
|
-
party:
|
|
33
|
-
room:
|
|
34
|
-
id:
|
|
19
|
+
host: config.host,
|
|
20
|
+
party: actorName,
|
|
21
|
+
room: instanceId,
|
|
22
|
+
id: this.id,
|
|
35
23
|
// Re-read on every (re)connect so a login/logout is picked up.
|
|
36
24
|
query: () => {
|
|
37
|
-
const token =
|
|
25
|
+
const token = config.getAuthToken();
|
|
38
26
|
return {
|
|
39
|
-
app_id:
|
|
40
|
-
handler:
|
|
27
|
+
app_id: config.appId,
|
|
28
|
+
handler: actorName,
|
|
41
29
|
...(token ? { token } : {}),
|
|
42
|
-
...(
|
|
30
|
+
...(config.functionsVersion ? { fv: config.functionsVersion } : {}),
|
|
43
31
|
};
|
|
44
32
|
},
|
|
45
33
|
});
|
|
@@ -77,36 +65,44 @@ class Room {
|
|
|
77
65
|
// not open; the watchdog above will reconnect
|
|
78
66
|
}
|
|
79
67
|
}, PING_MS);
|
|
80
|
-
return this;
|
|
81
68
|
}
|
|
82
69
|
subscribe(callback) {
|
|
83
|
-
if (!this.ws) {
|
|
84
|
-
throw new Error(`${this.actorName}:${this.instanceId}: connect() before subscribe()`);
|
|
85
|
-
}
|
|
86
70
|
this.listeners.add(callback);
|
|
87
71
|
return {
|
|
88
72
|
unsubscribe: () => { this.listeners.delete(callback); },
|
|
89
73
|
};
|
|
90
74
|
}
|
|
91
75
|
send(data) {
|
|
92
|
-
if (!this.ws) {
|
|
93
|
-
throw new Error(`${this.actorName}:${this.instanceId}: connect() before send()`);
|
|
94
|
-
}
|
|
95
76
|
this.ws.send(JSON.stringify(data));
|
|
96
77
|
}
|
|
97
78
|
close() {
|
|
98
|
-
var _a, _b;
|
|
99
79
|
if (this.heartbeat) {
|
|
100
80
|
clearInterval(this.heartbeat);
|
|
101
81
|
this.heartbeat = null;
|
|
102
82
|
}
|
|
103
83
|
this.listeners.clear();
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
this.connId = null;
|
|
107
|
-
(_b = this.onClose) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
84
|
+
this.ws.close();
|
|
85
|
+
this.onClose();
|
|
108
86
|
}
|
|
109
87
|
}
|
|
88
|
+
/** Handle for one actor instance: `connect()` opens the socket (idempotent). */
|
|
89
|
+
function makeActorRef(actorName, instanceId, config, connections) {
|
|
90
|
+
let conn = null;
|
|
91
|
+
return {
|
|
92
|
+
connect(options) {
|
|
93
|
+
if (conn)
|
|
94
|
+
return conn;
|
|
95
|
+
const c = new Connection(actorName, instanceId, config, options, () => {
|
|
96
|
+
connections.delete(c);
|
|
97
|
+
if (conn === c)
|
|
98
|
+
conn = null; // allow a fresh connect() after close
|
|
99
|
+
});
|
|
100
|
+
conn = c;
|
|
101
|
+
connections.add(c);
|
|
102
|
+
return c;
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
110
106
|
/**
|
|
111
107
|
* Absolute host for the actor WebSocket. PartySocket needs an absolute host and
|
|
112
108
|
* can't resolve a relative/empty `serverUrl` (same-origin apps use a relative
|
|
@@ -117,27 +113,23 @@ export function resolveActorsHost(serverUrl, browserOrigin) {
|
|
|
117
113
|
return serverUrl && !serverUrl.startsWith("/") ? serverUrl : browserOrigin !== null && browserOrigin !== void 0 ? browserOrigin : serverUrl;
|
|
118
114
|
}
|
|
119
115
|
export function createActorsModule(config) {
|
|
120
|
-
// Live
|
|
121
|
-
// forgot to close() (each
|
|
122
|
-
const
|
|
116
|
+
// Live connections this client opened, so client.cleanup() can reclaim any the
|
|
117
|
+
// app forgot to close() (each connection removes itself here on close).
|
|
118
|
+
const connections = new Set();
|
|
123
119
|
const module = new Proxy({}, {
|
|
124
120
|
get(_, key) {
|
|
125
121
|
// Symbols and `then` resolve to undefined (so the module isn't mistaken
|
|
126
122
|
// for a thenable when awaited); any string key is an actor name.
|
|
127
123
|
if (typeof key !== "string" || key === "then")
|
|
128
124
|
return undefined;
|
|
129
|
-
return (instanceId) =>
|
|
130
|
-
const room = new Room(key, instanceId, config, () => rooms.delete(room));
|
|
131
|
-
rooms.add(room);
|
|
132
|
-
return room;
|
|
133
|
-
};
|
|
125
|
+
return (instanceId) => makeActorRef(key, instanceId, config, connections);
|
|
134
126
|
},
|
|
135
127
|
});
|
|
136
128
|
return {
|
|
137
129
|
module,
|
|
138
130
|
closeAll: () => {
|
|
139
|
-
for (const
|
|
140
|
-
|
|
131
|
+
for (const c of [...connections])
|
|
132
|
+
c.close();
|
|
141
133
|
},
|
|
142
134
|
};
|
|
143
135
|
}
|
|
@@ -32,7 +32,7 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
|
|
|
32
32
|
type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
|
|
33
33
|
toServer: infer O;
|
|
34
34
|
} ? O : unknown : unknown;
|
|
35
|
-
/** Options for {@link
|
|
35
|
+
/** Options for {@link ActorRef.connect}. */
|
|
36
36
|
export interface ActorConnectOptions {
|
|
37
37
|
/**
|
|
38
38
|
* The connection id — becomes the actor's `conn.id`. Supply a stable value
|
|
@@ -41,46 +41,52 @@ export interface ActorConnectOptions {
|
|
|
41
41
|
*/
|
|
42
42
|
id?: string;
|
|
43
43
|
}
|
|
44
|
-
/** Handle for one listener registered via {@link
|
|
44
|
+
/** Handle for one listener registered via {@link Connection.subscribe}. */
|
|
45
45
|
export interface ActorSubscription {
|
|
46
46
|
/** Remove this listener; other listeners and the socket stay live. */
|
|
47
47
|
unsubscribe(): void;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* A
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* A live connection to an actor instance, returned by {@link ActorRef.connect}.
|
|
51
|
+
* `subscribe`/`send` are always valid — you only get a `Connection` once the
|
|
52
|
+
* socket has been opened, so there's no pre-connect state to guard against.
|
|
53
53
|
*/
|
|
54
|
-
export interface
|
|
55
|
-
/** The connection id (the value the actor sees as `conn.id`).
|
|
54
|
+
export interface Connection<N extends string = string> {
|
|
55
|
+
/** The connection id (the value the actor sees as `conn.id`). */
|
|
56
56
|
readonly id: string;
|
|
57
|
-
/** Open the WebSocket (required before subscribe/send). Idempotent; returns this. */
|
|
58
|
-
connect(options?: ActorConnectOptions): this;
|
|
59
57
|
/** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
|
|
60
58
|
subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
|
|
61
|
-
/** Send a message.
|
|
59
|
+
/** Send a message. Buffered by the socket until it's open. */
|
|
62
60
|
send(data: ToServerFor<N>): void;
|
|
63
61
|
/** Tear down the socket, heartbeat, and all listeners. */
|
|
64
62
|
close(): void;
|
|
65
63
|
}
|
|
66
64
|
/**
|
|
67
|
-
*
|
|
68
|
-
* {@link
|
|
65
|
+
* A handle to one actor instance — `base44.actors.MyActor(id)`. Call
|
|
66
|
+
* {@link connect} to open the socket and get a {@link Connection}.
|
|
67
|
+
*/
|
|
68
|
+
export interface ActorRef<N extends string = string> {
|
|
69
|
+
/** Open the WebSocket and return the {@link Connection}. Idempotent. */
|
|
70
|
+
connect(options?: ActorConnectOptions): Connection<N>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Client for a single named Actor — call it with an instance id to get an
|
|
74
|
+
* {@link ActorRef}. Typed automatically when the actor is registered in
|
|
69
75
|
* {@link ActorRegistry}.
|
|
70
76
|
*/
|
|
71
77
|
export interface ActorClient<N extends string = string> {
|
|
72
|
-
(instanceId: string):
|
|
78
|
+
(instanceId: string): ActorRef<N>;
|
|
73
79
|
}
|
|
74
80
|
/**
|
|
75
81
|
* The actors module provides access to Cloudflare Durable Object-backed
|
|
76
82
|
* Actors deployed by the Base44 platform.
|
|
77
83
|
*
|
|
78
84
|
* ```typescript
|
|
79
|
-
* const
|
|
80
|
-
* const sub =
|
|
81
|
-
*
|
|
85
|
+
* const conn = base44.actors.MyActor("room-1").connect();
|
|
86
|
+
* const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
|
|
87
|
+
* conn.send({ type: "message", text: "hi" });
|
|
82
88
|
* sub.unsubscribe();
|
|
83
|
-
*
|
|
89
|
+
* conn.close();
|
|
84
90
|
* ```
|
|
85
91
|
*/
|
|
86
92
|
export type ActorsModule = {
|