Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from "./types.js";
export type {
EntitiesModule,
EntityHandler,
EntityTypeRegistry,
RealtimeEventType,
RealtimeEvent,
RealtimeCallback,
Expand Down Expand Up @@ -71,10 +72,14 @@ export type {
CreateFileSignedUrlResult,
} from "./modules/integrations.types.js";

export type { FunctionsModule } from "./modules/functions.types.js";
export type {
FunctionsModule,
FunctionNameRegistry,
} from "./modules/functions.types.js";

export type {
AgentsModule,
AgentNameRegistry,
AgentConversation,
AgentMessage,
AgentMessageReasoning,
Expand Down
17 changes: 15 additions & 2 deletions src/modules/agents.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import { AxiosInstance } from "axios";
import { RoomsSocket } from "../utils/socket-utils.js";
import { ModelFilterParams } from "../types.js";

/**
* Registry of agent names.
* Augment this interface to enable autocomplete for agent names.
*/
export interface AgentNameRegistry {}

/**
* Agent name type - uses registry keys if augmented, otherwise string.
*/
export type AgentName = keyof AgentNameRegistry extends never
? string
: keyof AgentNameRegistry;

/**
* Reasoning information for an agent message.
*
Expand Down Expand Up @@ -135,7 +148,7 @@ export interface AgentMessage {
*/
export interface CreateConversationParams {
/** The name of the agent to create a conversation with. */
agent_name: string;
agent_name: AgentName;
/** Optional metadata to attach to the conversation. */
metadata?: Record<string, any>;
}
Expand Down Expand Up @@ -370,5 +383,5 @@ export interface AgentsModule {
* // User can open this URL to start a WhatsApp conversation
* ```
*/
getWhatsAppConnectURL(agentName: string): string;
getWhatsAppConnectURL(agentName: AgentName): string;
}
38 changes: 22 additions & 16 deletions src/modules/entities.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export type SortField<T> =
| `+${keyof T & string}`
| `-${keyof T & string}`;

/**
* Registry mapping entity names to their TypeScript types.
* Augment this interface to enable type-safe entity access.
*/
export interface EntityTypeRegistry {}

/**
* Entity handler providing CRUD operations for a specific entity type.
*
Expand Down Expand Up @@ -303,7 +309,7 @@ export interface EntityHandler<T = any> {
* status: 'completed',
* priority: 'low'
* });
* console.log('Deleted:', result);
* console.log('Deleted:', result.deleted);
* ```
*/
deleteMany(query: Partial<T>): Promise<DeleteManyResult>;
Expand Down Expand Up @@ -382,6 +388,20 @@ export interface EntityHandler<T = any> {
subscribe(callback: RealtimeCallback<T>): () => void;
}

/**
* Typed entities module - maps registry keys to typed handlers.
*/
type TypedEntitiesModule = {
[K in keyof EntityTypeRegistry]: EntityHandler<EntityTypeRegistry[K]>;
};

/**
* Dynamic entities module - allows any entity name with untyped handler.
*/
type DynamicEntitiesModule = {
[entityName: string]: EntityHandler<any>;
};

/**
* Entities module for managing app data.
*
Expand Down Expand Up @@ -415,18 +435,4 @@ export interface EntityHandler<T = any> {
* const allUsers = await base44.asServiceRole.entities.User.list();
* ```
*/
export interface EntitiesModule {
/**
* Access any entity by name.
*
* Use this to access entities defined in the app.
*
* @example
* ```typescript
* // Access entities dynamically
* base44.entities.MyEntity
* base44.entities.AnotherEntity
* ```
*/
[entityName: string]: EntityHandler<any>;
}
export type EntitiesModule = TypedEntitiesModule & DynamicEntitiesModule;
15 changes: 14 additions & 1 deletion src/modules/functions.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/**
* Registry of function names.
* Augment this interface to enable autocomplete for function names.
*/
export interface FunctionNameRegistry {}

/**
* Function name type - uses registry keys if augmented, otherwise string.
*/
export type FunctionName = keyof FunctionNameRegistry extends never
? string
: keyof FunctionNameRegistry;

/**
* Functions module for invoking custom backend functions.
*
Expand Down Expand Up @@ -46,5 +59,5 @@ export interface FunctionsModule {
* };
* ```
*/
invoke(functionName: string, data: Record<string, any>): Promise<any>;
invoke(functionName: FunctionName, data?: Record<string, any>): Promise<any>;
}