@base44-preview/sdk 0.8.49-pr.289.e36026d → 0.8.50-pr.290.00d2bf0
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
CHANGED
|
@@ -25,8 +25,8 @@ export interface Storage {
|
|
|
25
25
|
get<T>(key: string): Promise<T | undefined>;
|
|
26
26
|
put(key: string, value: unknown): Promise<void>;
|
|
27
27
|
delete(key: string): Promise<boolean>;
|
|
28
|
-
/** Wipe the
|
|
29
|
-
*
|
|
28
|
+
/** Wipe the room's entire persisted storage (match-end cleanup). Safe: a
|
|
29
|
+
* later rejoin re-bootstraps exactly like a brand-new room. */
|
|
30
30
|
deleteAll(): Promise<void>;
|
|
31
31
|
}
|
|
32
32
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, Change
|
|
|
9
9
|
export type { IntegrationsModule, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
|
|
11
11
|
export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
|
|
12
|
-
export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
|
|
12
|
+
export type { AiGatewayModule, AiGatewayConnection, AiGatewayConnectionOptions, } from "./modules/ai-gateway.types.js";
|
|
13
13
|
export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
14
14
|
export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from "./modules/app.types.js";
|
|
15
15
|
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Extend this interface to add typed `subscribe` callbacks and `send` payloads
|
|
3
|
+
* for your deployed Actors.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* defines incoming messages that a client sends to the actor. `toClient` defines
|
|
7
|
-
* outgoing messages that the actor sends to connected clients.
|
|
8
|
-
*
|
|
9
|
-
* To generate types from deployed actors instead, use the
|
|
10
|
-
* [`types generate`](/developers/references/cli/commands/types-generate) CLI command.
|
|
11
|
-
* See [Typing messages in the client](/developers/backend/resources/actors/overview#typing-messages-in-the-client)
|
|
12
|
-
* for how to define your message types.
|
|
5
|
+
* This is separate from {@link ActorNameRegistry} (which is auto-generated
|
|
6
|
+
* by `base44 types generate`), so there are no conflicts.
|
|
13
7
|
*
|
|
14
8
|
* @example
|
|
15
9
|
* ```typescript
|
|
@@ -26,11 +20,8 @@
|
|
|
26
20
|
export interface ActorRegistry {
|
|
27
21
|
}
|
|
28
22
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* The generated names provide autocomplete for deployed actors. To define
|
|
33
|
-
* incoming and outgoing message types manually, augment [ActorRegistry](#actorregistry).
|
|
23
|
+
* Auto-populated by `base44 types generate` with the names of your deployed actors.
|
|
24
|
+
* Do not edit this interface manually — use {@link ActorRegistry} for message types.
|
|
34
25
|
*/
|
|
35
26
|
export interface ActorNameRegistry {
|
|
36
27
|
}
|
|
@@ -41,136 +32,71 @@ type ToClientFor<N extends string> = N extends keyof ActorRegistry ? ActorRegist
|
|
|
41
32
|
type ToServerFor<N extends string> = N extends keyof ActorRegistry ? ActorRegistry[N] extends {
|
|
42
33
|
toServer: infer O;
|
|
43
34
|
} ? O : unknown : unknown;
|
|
44
|
-
/**
|
|
45
|
-
* Options for [ActorRef.connect](#connect).
|
|
46
|
-
*/
|
|
35
|
+
/** Options for {@link ActorRef.connect}. */
|
|
47
36
|
export interface ActorConnectOptions {
|
|
48
37
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* can recognize the same client if it reconnects. If omitted, the SDK generates one.
|
|
53
|
-
*
|
|
54
|
-
* See [Connection ID](/developers/backend/resources/actors/overview#connection-id)
|
|
55
|
-
* for more details.
|
|
38
|
+
* The connection id — becomes the actor's `conn.id`. Supply a stable value
|
|
39
|
+
* (e.g. persisted per tab) so a reconnect reuses the same server-side
|
|
40
|
+
* identity; omit for an auto-generated per-connection id.
|
|
56
41
|
*/
|
|
57
42
|
id?: string;
|
|
58
43
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Represents an outgoing-message listener registered with
|
|
61
|
-
* [Connection.subscribe](#subscribe).
|
|
62
|
-
*/
|
|
44
|
+
/** Handle for one listener registered via {@link Connection.subscribe}. */
|
|
63
45
|
export interface ActorSubscription {
|
|
64
|
-
/**
|
|
65
|
-
* Removes this listener. Other listeners and the socket stay open.
|
|
66
|
-
*/
|
|
46
|
+
/** Remove this listener; other listeners and the socket stay live. */
|
|
67
47
|
unsubscribe(): void;
|
|
68
48
|
}
|
|
69
49
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* The socket buffers messages sent during connection setup until it opens.
|
|
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.
|
|
74
53
|
*/
|
|
75
54
|
export interface Connection<N extends string = string> {
|
|
76
|
-
/**
|
|
55
|
+
/** The connection id (the value the actor sees as `conn.id`). */
|
|
77
56
|
readonly id: string;
|
|
78
|
-
/**
|
|
79
|
-
* Registers a listener for outgoing messages from the actor.
|
|
80
|
-
*
|
|
81
|
-
* You can register multiple listeners on the same connection.
|
|
82
|
-
*
|
|
83
|
-
* @param callback - Called with each outgoing message sent to this connection.
|
|
84
|
-
* @returns A handle you can use to remove this listener without closing the socket.
|
|
85
|
-
*/
|
|
57
|
+
/** Register a message listener. Multiple are allowed; returns a per-listener unsubscribe. */
|
|
86
58
|
subscribe(callback: (data: ToClientFor<N>) => void): ActorSubscription;
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* The socket buffers messages until it opens. After [close](#close), the socket
|
|
91
|
-
* drops further sends.
|
|
92
|
-
*
|
|
93
|
-
* @param data - Incoming message to send. Typed through [ActorRegistry](#actorregistry) when configured.
|
|
94
|
-
*/
|
|
59
|
+
/** Send a message. Buffered by the socket until it's open; dropped after
|
|
60
|
+
* {@link close}. */
|
|
95
61
|
send(data: ToServerFor<N>): void;
|
|
96
62
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* permanently. See [ActorRef.connect](#connect) for how to open a fresh connection.
|
|
63
|
+
* Tear down the socket, heartbeat, and all listeners. Safe to call more
|
|
64
|
+
* than once. A connection also closes itself when it fails permanently —
|
|
65
|
+
* see {@link ActorRef.connect}.
|
|
101
66
|
*/
|
|
102
67
|
close(): void;
|
|
103
68
|
}
|
|
104
69
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* Call [connect](#connect) to open the WebSocket and get a [Connection](#connection).
|
|
70
|
+
* A handle to one actor instance — `base44.actors.MyActor(id)`. Call
|
|
71
|
+
* {@link connect} to open the socket and get a {@link Connection}.
|
|
108
72
|
*/
|
|
109
73
|
export interface ActorRef<N extends string = string> {
|
|
110
74
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* Repeated calls return the same connection until it closes. After a permanent
|
|
114
|
-
* failure, such as a missing actor or denied connection, fix the cause and call
|
|
115
|
-
* `connect()` again. Add subscriptions to the new connection.
|
|
116
|
-
*
|
|
117
|
-
* See [Connect a client to a session](/developers/backend/resources/actors/samples#connect-a-client-to-a-session)
|
|
118
|
-
* for a sample flow.
|
|
75
|
+
* Open the WebSocket and return the {@link Connection}. Idempotent while the
|
|
76
|
+
* connection is open.
|
|
119
77
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
78
|
+
* A connection that fails permanently (for example, the actor doesn't exist
|
|
79
|
+
* or the caller isn't allowed to connect) closes itself and reports the
|
|
80
|
+
* error to the client's `onError` handler. Call `connect()` again after
|
|
81
|
+
* fixing the cause to get a fresh {@link Connection}, and re-subscribe.
|
|
122
82
|
*/
|
|
123
83
|
connect(options?: ActorConnectOptions): Connection<N>;
|
|
124
84
|
}
|
|
125
85
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* [ActorNameRegistry](#actornameregistry).
|
|
86
|
+
* Client for a single named Actor — call it with an instance id to get an
|
|
87
|
+
* {@link ActorRef}. Typed automatically when the actor is registered in
|
|
88
|
+
* {@link ActorRegistry}.
|
|
130
89
|
*/
|
|
131
90
|
export interface ActorClient<N extends string = string> {
|
|
132
|
-
/**
|
|
133
|
-
* Gets a reference to an actor session.
|
|
134
|
-
*
|
|
135
|
-
* Clients that specify the same actor name and session ID join the same session.
|
|
136
|
-
*
|
|
137
|
-
* @param instanceId - Session ID that identifies which session to connect to.
|
|
138
|
-
* @returns A reference to the actor session.
|
|
139
|
-
*/
|
|
140
91
|
(instanceId: string): ActorRef<N>;
|
|
141
92
|
}
|
|
142
93
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* With the Actors SDK module you can:
|
|
147
|
-
*
|
|
148
|
-
* - Connect to a session with `base44.actors.<ActorName>(sessionId).connect()`.
|
|
149
|
-
* - Subscribe to messages the actor sends using [Connection.subscribe](#subscribe),
|
|
150
|
-
* either broadcast to all clients or sent directly to your client.
|
|
151
|
-
* - Send messages to the actor with [Connection.send](#send).
|
|
152
|
-
* - Share a session across multiple clients: any clients with the same actor
|
|
153
|
-
* name and session ID connect to the same session.
|
|
154
|
-
* - Type your messages using [ActorRegistry](#actorregistry) for autocomplete
|
|
155
|
-
* and compile-time safety.
|
|
156
|
-
*
|
|
157
|
-
* Learn more about [actors](/developers/backend/resources/actors/overview).
|
|
158
|
-
*
|
|
159
|
-
* ## Authentication modes
|
|
160
|
-
*
|
|
161
|
-
* This module is available in anonymous or user authentication mode.
|
|
162
|
-
* Apps that require login can reject anonymous connections in the actor's `handleConnect()` method.
|
|
163
|
-
* Learn more about [managing client connections](/developers/backend/resources/actors/samples#manage-client-connections).
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
* @example
|
|
167
|
-
*
|
|
168
|
-
* The following example displays the general lifecycle of a client connected to an actor named `Chat`:
|
|
94
|
+
* The actors module provides access to Cloudflare Durable Object-backed
|
|
95
|
+
* Actors deployed by the Base44 platform.
|
|
169
96
|
*
|
|
170
97
|
* ```typescript
|
|
171
|
-
*
|
|
172
|
-
* const
|
|
173
|
-
* const sub = conn.subscribe((msg) => console.log(msg));
|
|
98
|
+
* const conn = base44.actors.MyActor("room-1").connect();
|
|
99
|
+
* const sub = conn.subscribe((msg) => console.log(msg)); // typed via ActorRegistry
|
|
174
100
|
* conn.send({ type: "message", text: "hi" });
|
|
175
101
|
* sub.unsubscribe();
|
|
176
102
|
* conn.close();
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { getAccessToken } from "../utils/auth-utils.js";
|
|
2
|
+
const PROVIDER_PATHS = {
|
|
3
|
+
openai: "openai",
|
|
4
|
+
typesafe: "typesafe",
|
|
5
|
+
};
|
|
2
6
|
export function createAiGatewayModule({ serverUrl, token, appId, }) {
|
|
3
|
-
const connection = () => {
|
|
7
|
+
const connection = ({ provider = "openai" } = {}) => {
|
|
4
8
|
var _a;
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
if (!Object.prototype.hasOwnProperty.call(PROVIDER_PATHS, provider)) {
|
|
10
|
+
throw new Error(`Unsupported AI Gateway provider: ${provider}`);
|
|
11
|
+
}
|
|
12
|
+
const providerPath = PROVIDER_PATHS[provider];
|
|
13
|
+
return {
|
|
14
|
+
baseURL: `${serverUrl}/api/apps/${appId}/ai/${providerPath}/v1`,
|
|
7
15
|
token: (_a = token !== null && token !== void 0 ? token : getAccessToken()) !== null && _a !== void 0 ? _a : "",
|
|
8
|
-
}
|
|
16
|
+
};
|
|
9
17
|
};
|
|
10
18
|
return {
|
|
11
19
|
connection,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Connection details for the Base44 AI Gateway.
|
|
3
3
|
*/
|
|
4
4
|
export interface AiGatewayConnection {
|
|
5
|
-
/** Base URL of the gateway
|
|
5
|
+
/** Base URL of the selected gateway provider. */
|
|
6
6
|
baseURL: string;
|
|
7
7
|
/**
|
|
8
8
|
* Bearer token that authenticates the request. Empty string when the caller is
|
|
@@ -10,6 +10,11 @@ export interface AiGatewayConnection {
|
|
|
10
10
|
*/
|
|
11
11
|
token: string;
|
|
12
12
|
}
|
|
13
|
+
/** Options for selecting an AI Gateway provider. */
|
|
14
|
+
export interface AiGatewayConnectionOptions {
|
|
15
|
+
/** Gateway provider to connect to. Defaults to `openai`. */
|
|
16
|
+
provider?: "openai" | "typesafe";
|
|
17
|
+
}
|
|
13
18
|
/**
|
|
14
19
|
* Configuration for the AI Gateway module.
|
|
15
20
|
* @internal
|
|
@@ -34,13 +39,17 @@ export interface AiGatewayModuleConfig {
|
|
|
34
39
|
* against the provider directly, no separate account, API key, or billing
|
|
35
40
|
* setup with the underlying model provider required.
|
|
36
41
|
*
|
|
42
|
+
* By default, `connection()` uses the OpenAI-compatible provider. Pass
|
|
43
|
+
* `{ provider: "typesafe" }` to connect to TypeSafe for structured evaluations
|
|
44
|
+
* with `@ai-sdk/typesafe-ai`.
|
|
45
|
+
*
|
|
37
46
|
* Call `connection()` from a backend function rather than the browser. This
|
|
38
47
|
* keeps your instructions, tools, and business logic server-side, and lets
|
|
39
48
|
* you enforce your own auth, rate, and spend limits around the call. The
|
|
40
49
|
* `token` it returns is the caller's regular session token, the same one
|
|
41
50
|
* used for every other SDK call.
|
|
42
51
|
*
|
|
43
|
-
* ##
|
|
52
|
+
* ## OpenAI-compatible models
|
|
44
53
|
*
|
|
45
54
|
* You can use any of the [models available through `InvokeLLM`](/developers/references/sdk/docs/type-aliases/integrations#invokellm).
|
|
46
55
|
* Pass `'automatic'` to let Base44 choose one, or pin a specific model such
|
|
@@ -69,7 +78,9 @@ export interface AiGatewayModule {
|
|
|
69
78
|
/**
|
|
70
79
|
* Gets the connection details for the Base44 AI Gateway.
|
|
71
80
|
*
|
|
72
|
-
* Returns the `baseURL` and `token` to pass to
|
|
81
|
+
* Returns the `baseURL` and `token` to pass to the selected provider client.
|
|
82
|
+
*
|
|
83
|
+
* @param options - Provider selection. Omit it to use the OpenAI-compatible gateway.
|
|
73
84
|
*
|
|
74
85
|
* @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
|
|
75
86
|
*
|
|
@@ -135,5 +146,5 @@ export interface AiGatewayModule {
|
|
|
135
146
|
* await agent.generate({ prompt: `Review this return request: ${JSON.stringify(returnRequest)}` });
|
|
136
147
|
* ```
|
|
137
148
|
*/
|
|
138
|
-
connection(): AiGatewayConnection;
|
|
149
|
+
connection(options?: AiGatewayConnectionOptions): AiGatewayConnection;
|
|
139
150
|
}
|
|
@@ -950,6 +950,16 @@ type DynamicEntitiesModule = {
|
|
|
950
950
|
* - **Anonymous or User authentication** (`base44.entities`): Access is scoped to the current user's permissions. Anonymous users can only access public entities, while authenticated users can access entities they have permission to view or modify.
|
|
951
951
|
* - **Service role authentication** (`base44.asServiceRole.entities`): Operations bypass entity access rules and field-level security entirely. Can read and write any record in any entity.
|
|
952
952
|
*
|
|
953
|
+
* ## How denied reads and writes differ
|
|
954
|
+
*
|
|
955
|
+
* Row-level security handles reads and writes differently.
|
|
956
|
+
*
|
|
957
|
+
* | Operation | When a rule denies it |
|
|
958
|
+
* | --- | --- |
|
|
959
|
+
* | `list()`, `filter()` | Returns an empty result, the same as if nothing matched. No error is thrown. |
|
|
960
|
+
* | `get()` | Throws a not-found error, whether or not the record exists. |
|
|
961
|
+
* | `create()`, `update()` | Throws a permission error with HTTP 403. |
|
|
962
|
+
*
|
|
953
963
|
* ## Entity Handlers
|
|
954
964
|
*
|
|
955
965
|
* An entity handler is the object you get when you access an entity through `base44.entities.EntityName`. Every entity in your app automatically gets a handler with CRUD methods for managing records.
|