@ragable/sdk 0.7.9 → 0.8.0
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/index.d.mts +128 -4
- package/dist/index.d.ts +128 -4
- package/dist/index.js +104 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1246,6 +1246,98 @@ declare function streamObjectFromContext<T = unknown>(ctx: InferenceRequestConte
|
|
|
1246
1246
|
*/
|
|
1247
1247
|
declare function wrapStreamTextAsObject<T = unknown>(inner: StreamTextResult): StreamObjectResult<T>;
|
|
1248
1248
|
|
|
1249
|
+
/**
|
|
1250
|
+
* Backend "edge functions".
|
|
1251
|
+
*
|
|
1252
|
+
* A function is a single file in the project's `/functions` folder whose name is
|
|
1253
|
+
* the function name and whose **default export is the handler**:
|
|
1254
|
+
*
|
|
1255
|
+
* ```ts
|
|
1256
|
+
* // /functions/getUsers.ts
|
|
1257
|
+
* import type { RagableFunctionContext } from "@ragable/sdk";
|
|
1258
|
+
*
|
|
1259
|
+
* export default async function getUsers(
|
|
1260
|
+
* input: { limit?: number },
|
|
1261
|
+
* context: RagableFunctionContext,
|
|
1262
|
+
* ) {
|
|
1263
|
+
* const res = await fetch("https://api.example.com/users", {
|
|
1264
|
+
* headers: { Authorization: `Bearer ${context.env.API_KEY}` },
|
|
1265
|
+
* });
|
|
1266
|
+
* return (await res.json()).slice(0, input.limit ?? 20);
|
|
1267
|
+
* }
|
|
1268
|
+
* ```
|
|
1269
|
+
*
|
|
1270
|
+
* Saving the file deploys it (near-instant). It runs **server-side** — so secrets
|
|
1271
|
+
* stay off the client and there are no browser CORS limits — and is invoked from
|
|
1272
|
+
* the browser with `client.functions.getUsers({ limit: 5 })`.
|
|
1273
|
+
*
|
|
1274
|
+
* The handler's second argument (`context`) is injected by the server; callers
|
|
1275
|
+
* pass only `input`.
|
|
1276
|
+
*/
|
|
1277
|
+
/**
|
|
1278
|
+
* Server-injected second argument to every function handler. Never constructed
|
|
1279
|
+
* on the client — the values come from the backend at invocation time.
|
|
1280
|
+
*/
|
|
1281
|
+
interface RagableFunctionContext {
|
|
1282
|
+
/**
|
|
1283
|
+
* Secrets for this function, parsed from the project's `/functions/.env`.
|
|
1284
|
+
* Server-only: this file is read at invoke time and never bundled into the
|
|
1285
|
+
* browser app. Empty when no `/functions/.env` exists.
|
|
1286
|
+
*/
|
|
1287
|
+
env: Record<string, string>;
|
|
1288
|
+
/** Metadata about the invoking HTTP request. */
|
|
1289
|
+
request: {
|
|
1290
|
+
method: string;
|
|
1291
|
+
headers: Record<string, string>;
|
|
1292
|
+
};
|
|
1293
|
+
/**
|
|
1294
|
+
* End-user auth forwarded from the caller. `token` is the bearer the browser
|
|
1295
|
+
* client was holding (an end-user access token or the data static key), or
|
|
1296
|
+
* `null` for anonymous calls.
|
|
1297
|
+
*/
|
|
1298
|
+
auth: {
|
|
1299
|
+
token: string | null;
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* The shape a `/functions/<name>.ts` default export must satisfy. Type the
|
|
1304
|
+
* `input` parameter as optional (`input?: Foo`) when callers may omit it.
|
|
1305
|
+
*/
|
|
1306
|
+
type RagableFunctionHandler<Input = any, Output = any> = (input: Input, context: RagableFunctionContext) => Output | Promise<Output>;
|
|
1307
|
+
/**
|
|
1308
|
+
* A project's function map: function name → handler. Generated as `AppFunctions`.
|
|
1309
|
+
* The constraint is intentionally loose (any function shape) so a handler that
|
|
1310
|
+
* deviates from `(input, context)` never breaks the generated client as a whole;
|
|
1311
|
+
* the per-call typing in {@link RagableFunctionCall} adapts to each signature.
|
|
1312
|
+
*/
|
|
1313
|
+
type RagableFunctions = Record<string, (...args: any[]) => any>;
|
|
1314
|
+
/** Permissive default used when no generated `AppFunctions` is supplied. */
|
|
1315
|
+
interface DefaultRagableFunctions {
|
|
1316
|
+
[name: string]: (...args: any[]) => any;
|
|
1317
|
+
}
|
|
1318
|
+
/** Per-call options for an invocation. */
|
|
1319
|
+
interface RagableFunctionInvokeOptions {
|
|
1320
|
+
signal?: AbortSignal;
|
|
1321
|
+
headers?: HeadersInit;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* The browser-side call signature derived from a server handler `H`: the server
|
|
1325
|
+
* injects `context`, so the caller passes only `input`. `input` is optional when
|
|
1326
|
+
* the handler's input type permits `undefined`.
|
|
1327
|
+
*/
|
|
1328
|
+
type RagableFunctionCall<H> = H extends (input: infer I, ...rest: any[]) => infer R ? undefined extends I ? (input?: I, options?: RagableFunctionInvokeOptions) => Promise<Awaited<R>> : (input: I, options?: RagableFunctionInvokeOptions) => Promise<Awaited<R>> : (input?: unknown, options?: RagableFunctionInvokeOptions) => Promise<unknown>;
|
|
1329
|
+
/**
|
|
1330
|
+
* The type of `client.functions`: a typed callable per function in `F`, plus an
|
|
1331
|
+
* `invoke(name, input?)` escape hatch for dynamic dispatch. (A function literally
|
|
1332
|
+
* named `invoke` is therefore reserved.)
|
|
1333
|
+
*/
|
|
1334
|
+
type FunctionInvoker<F extends RagableFunctions = DefaultRagableFunctions> = {
|
|
1335
|
+
[K in keyof F]: RagableFunctionCall<F[K]>;
|
|
1336
|
+
} & {
|
|
1337
|
+
/** Invoke a function by name. Useful when the name is dynamic. */
|
|
1338
|
+
invoke<Result = unknown>(name: string, input?: unknown, options?: RagableFunctionInvokeOptions): Promise<Result>;
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1249
1341
|
/** Canonical browser/server API base (`…/api`, no trailing slash). */
|
|
1250
1342
|
declare function normalizeBrowserApiBase(): string;
|
|
1251
1343
|
type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
@@ -1887,6 +1979,33 @@ declare class RagableBrowserMailClient {
|
|
|
1887
1979
|
/** Fetch a single message in full (headers + decoded text/html body). */
|
|
1888
1980
|
getMessage(messageId: string): Promise<MailMessageDetail>;
|
|
1889
1981
|
}
|
|
1982
|
+
/**
|
|
1983
|
+
* Invokes the project's backend edge functions (handlers in `/functions/<name>.ts`).
|
|
1984
|
+
*
|
|
1985
|
+
* Exposed on the client as a typed Proxy — `client.functions.<name>(input)` — so
|
|
1986
|
+
* each generated function name is a direct callable. Functions run server-side,
|
|
1987
|
+
* so calls can use secrets and reach any external API without browser CORS limits.
|
|
1988
|
+
*/
|
|
1989
|
+
declare class RagableBrowserFunctionsClient {
|
|
1990
|
+
private readonly options;
|
|
1991
|
+
private readonly auth;
|
|
1992
|
+
private readonly fetchImpl;
|
|
1993
|
+
constructor(options: RagableBrowserClientOptions, auth: RagableAuth | null);
|
|
1994
|
+
private requireWebsiteId;
|
|
1995
|
+
private toUrl;
|
|
1996
|
+
/**
|
|
1997
|
+
* Best-effort end-user bearer, forwarded to the function as `context.auth.token`.
|
|
1998
|
+
* Functions are public, so this never throws — anonymous calls send no token.
|
|
1999
|
+
*/
|
|
2000
|
+
private getOptionalToken;
|
|
2001
|
+
/**
|
|
2002
|
+
* Invoke a function by name. Prefer the typed `client.functions.<name>(input)`
|
|
2003
|
+
* accessors; use this when the name is dynamic.
|
|
2004
|
+
*/
|
|
2005
|
+
invoke<Result = unknown>(name: string, input?: unknown, options?: RagableFunctionInvokeOptions): Promise<Result>;
|
|
2006
|
+
/** Build the typed Proxy exposed as `client.functions`. */
|
|
2007
|
+
asInvoker<F extends RagableFunctions = DefaultRagableFunctions>(): FunctionInvoker<F>;
|
|
2008
|
+
}
|
|
1890
2009
|
interface AgentConversationMessage {
|
|
1891
2010
|
role: "user" | "assistant";
|
|
1892
2011
|
content: string;
|
|
@@ -2019,7 +2138,7 @@ interface AgentPublicChatParams extends AgentChatParams {
|
|
|
2019
2138
|
triggerSubtype?: string;
|
|
2020
2139
|
triggerNodeId?: string;
|
|
2021
2140
|
}
|
|
2022
|
-
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser> {
|
|
2141
|
+
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions> {
|
|
2023
2142
|
readonly agents: RagableBrowserAgentsClient;
|
|
2024
2143
|
readonly ai: RagableBrowserAiClient;
|
|
2025
2144
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
@@ -2027,6 +2146,11 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
2027
2146
|
readonly db: RagableBrowserDatabaseClient<Database>;
|
|
2028
2147
|
readonly storage: RagableBrowserStorageClient;
|
|
2029
2148
|
readonly mail: RagableBrowserMailClient;
|
|
2149
|
+
/**
|
|
2150
|
+
* Backend edge functions — call a `/functions/<name>.ts` handler with
|
|
2151
|
+
* `client.functions.<name>(input)`. Runs server-side. See {@link FunctionInvoker}.
|
|
2152
|
+
*/
|
|
2153
|
+
readonly functions: FunctionInvoker<Functions>;
|
|
2030
2154
|
readonly transport: Transport;
|
|
2031
2155
|
private readonly _ragableAuth;
|
|
2032
2156
|
constructor(options: RagableBrowserClientOptions);
|
|
@@ -2034,7 +2158,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
2034
2158
|
from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
|
|
2035
2159
|
destroy(): void;
|
|
2036
2160
|
}
|
|
2037
|
-
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
2161
|
+
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2038
2162
|
declare const createRagableBrowserClient: typeof createBrowserClient;
|
|
2039
2163
|
|
|
2040
2164
|
/**
|
|
@@ -2065,6 +2189,6 @@ declare function readSseStream(body: ReadableStream<Uint8Array>): AsyncGenerator
|
|
|
2065
2189
|
*/
|
|
2066
2190
|
declare function tryParsePartialJson(text: string): unknown | undefined;
|
|
2067
2191
|
|
|
2068
|
-
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
2192
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2069
2193
|
|
|
2070
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FinishReason, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
|
2194
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -1246,6 +1246,98 @@ declare function streamObjectFromContext<T = unknown>(ctx: InferenceRequestConte
|
|
|
1246
1246
|
*/
|
|
1247
1247
|
declare function wrapStreamTextAsObject<T = unknown>(inner: StreamTextResult): StreamObjectResult<T>;
|
|
1248
1248
|
|
|
1249
|
+
/**
|
|
1250
|
+
* Backend "edge functions".
|
|
1251
|
+
*
|
|
1252
|
+
* A function is a single file in the project's `/functions` folder whose name is
|
|
1253
|
+
* the function name and whose **default export is the handler**:
|
|
1254
|
+
*
|
|
1255
|
+
* ```ts
|
|
1256
|
+
* // /functions/getUsers.ts
|
|
1257
|
+
* import type { RagableFunctionContext } from "@ragable/sdk";
|
|
1258
|
+
*
|
|
1259
|
+
* export default async function getUsers(
|
|
1260
|
+
* input: { limit?: number },
|
|
1261
|
+
* context: RagableFunctionContext,
|
|
1262
|
+
* ) {
|
|
1263
|
+
* const res = await fetch("https://api.example.com/users", {
|
|
1264
|
+
* headers: { Authorization: `Bearer ${context.env.API_KEY}` },
|
|
1265
|
+
* });
|
|
1266
|
+
* return (await res.json()).slice(0, input.limit ?? 20);
|
|
1267
|
+
* }
|
|
1268
|
+
* ```
|
|
1269
|
+
*
|
|
1270
|
+
* Saving the file deploys it (near-instant). It runs **server-side** — so secrets
|
|
1271
|
+
* stay off the client and there are no browser CORS limits — and is invoked from
|
|
1272
|
+
* the browser with `client.functions.getUsers({ limit: 5 })`.
|
|
1273
|
+
*
|
|
1274
|
+
* The handler's second argument (`context`) is injected by the server; callers
|
|
1275
|
+
* pass only `input`.
|
|
1276
|
+
*/
|
|
1277
|
+
/**
|
|
1278
|
+
* Server-injected second argument to every function handler. Never constructed
|
|
1279
|
+
* on the client — the values come from the backend at invocation time.
|
|
1280
|
+
*/
|
|
1281
|
+
interface RagableFunctionContext {
|
|
1282
|
+
/**
|
|
1283
|
+
* Secrets for this function, parsed from the project's `/functions/.env`.
|
|
1284
|
+
* Server-only: this file is read at invoke time and never bundled into the
|
|
1285
|
+
* browser app. Empty when no `/functions/.env` exists.
|
|
1286
|
+
*/
|
|
1287
|
+
env: Record<string, string>;
|
|
1288
|
+
/** Metadata about the invoking HTTP request. */
|
|
1289
|
+
request: {
|
|
1290
|
+
method: string;
|
|
1291
|
+
headers: Record<string, string>;
|
|
1292
|
+
};
|
|
1293
|
+
/**
|
|
1294
|
+
* End-user auth forwarded from the caller. `token` is the bearer the browser
|
|
1295
|
+
* client was holding (an end-user access token or the data static key), or
|
|
1296
|
+
* `null` for anonymous calls.
|
|
1297
|
+
*/
|
|
1298
|
+
auth: {
|
|
1299
|
+
token: string | null;
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* The shape a `/functions/<name>.ts` default export must satisfy. Type the
|
|
1304
|
+
* `input` parameter as optional (`input?: Foo`) when callers may omit it.
|
|
1305
|
+
*/
|
|
1306
|
+
type RagableFunctionHandler<Input = any, Output = any> = (input: Input, context: RagableFunctionContext) => Output | Promise<Output>;
|
|
1307
|
+
/**
|
|
1308
|
+
* A project's function map: function name → handler. Generated as `AppFunctions`.
|
|
1309
|
+
* The constraint is intentionally loose (any function shape) so a handler that
|
|
1310
|
+
* deviates from `(input, context)` never breaks the generated client as a whole;
|
|
1311
|
+
* the per-call typing in {@link RagableFunctionCall} adapts to each signature.
|
|
1312
|
+
*/
|
|
1313
|
+
type RagableFunctions = Record<string, (...args: any[]) => any>;
|
|
1314
|
+
/** Permissive default used when no generated `AppFunctions` is supplied. */
|
|
1315
|
+
interface DefaultRagableFunctions {
|
|
1316
|
+
[name: string]: (...args: any[]) => any;
|
|
1317
|
+
}
|
|
1318
|
+
/** Per-call options for an invocation. */
|
|
1319
|
+
interface RagableFunctionInvokeOptions {
|
|
1320
|
+
signal?: AbortSignal;
|
|
1321
|
+
headers?: HeadersInit;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* The browser-side call signature derived from a server handler `H`: the server
|
|
1325
|
+
* injects `context`, so the caller passes only `input`. `input` is optional when
|
|
1326
|
+
* the handler's input type permits `undefined`.
|
|
1327
|
+
*/
|
|
1328
|
+
type RagableFunctionCall<H> = H extends (input: infer I, ...rest: any[]) => infer R ? undefined extends I ? (input?: I, options?: RagableFunctionInvokeOptions) => Promise<Awaited<R>> : (input: I, options?: RagableFunctionInvokeOptions) => Promise<Awaited<R>> : (input?: unknown, options?: RagableFunctionInvokeOptions) => Promise<unknown>;
|
|
1329
|
+
/**
|
|
1330
|
+
* The type of `client.functions`: a typed callable per function in `F`, plus an
|
|
1331
|
+
* `invoke(name, input?)` escape hatch for dynamic dispatch. (A function literally
|
|
1332
|
+
* named `invoke` is therefore reserved.)
|
|
1333
|
+
*/
|
|
1334
|
+
type FunctionInvoker<F extends RagableFunctions = DefaultRagableFunctions> = {
|
|
1335
|
+
[K in keyof F]: RagableFunctionCall<F[K]>;
|
|
1336
|
+
} & {
|
|
1337
|
+
/** Invoke a function by name. Useful when the name is dynamic. */
|
|
1338
|
+
invoke<Result = unknown>(name: string, input?: unknown, options?: RagableFunctionInvokeOptions): Promise<Result>;
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1249
1341
|
/** Canonical browser/server API base (`…/api`, no trailing slash). */
|
|
1250
1342
|
declare function normalizeBrowserApiBase(): string;
|
|
1251
1343
|
type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
@@ -1887,6 +1979,33 @@ declare class RagableBrowserMailClient {
|
|
|
1887
1979
|
/** Fetch a single message in full (headers + decoded text/html body). */
|
|
1888
1980
|
getMessage(messageId: string): Promise<MailMessageDetail>;
|
|
1889
1981
|
}
|
|
1982
|
+
/**
|
|
1983
|
+
* Invokes the project's backend edge functions (handlers in `/functions/<name>.ts`).
|
|
1984
|
+
*
|
|
1985
|
+
* Exposed on the client as a typed Proxy — `client.functions.<name>(input)` — so
|
|
1986
|
+
* each generated function name is a direct callable. Functions run server-side,
|
|
1987
|
+
* so calls can use secrets and reach any external API without browser CORS limits.
|
|
1988
|
+
*/
|
|
1989
|
+
declare class RagableBrowserFunctionsClient {
|
|
1990
|
+
private readonly options;
|
|
1991
|
+
private readonly auth;
|
|
1992
|
+
private readonly fetchImpl;
|
|
1993
|
+
constructor(options: RagableBrowserClientOptions, auth: RagableAuth | null);
|
|
1994
|
+
private requireWebsiteId;
|
|
1995
|
+
private toUrl;
|
|
1996
|
+
/**
|
|
1997
|
+
* Best-effort end-user bearer, forwarded to the function as `context.auth.token`.
|
|
1998
|
+
* Functions are public, so this never throws — anonymous calls send no token.
|
|
1999
|
+
*/
|
|
2000
|
+
private getOptionalToken;
|
|
2001
|
+
/**
|
|
2002
|
+
* Invoke a function by name. Prefer the typed `client.functions.<name>(input)`
|
|
2003
|
+
* accessors; use this when the name is dynamic.
|
|
2004
|
+
*/
|
|
2005
|
+
invoke<Result = unknown>(name: string, input?: unknown, options?: RagableFunctionInvokeOptions): Promise<Result>;
|
|
2006
|
+
/** Build the typed Proxy exposed as `client.functions`. */
|
|
2007
|
+
asInvoker<F extends RagableFunctions = DefaultRagableFunctions>(): FunctionInvoker<F>;
|
|
2008
|
+
}
|
|
1890
2009
|
interface AgentConversationMessage {
|
|
1891
2010
|
role: "user" | "assistant";
|
|
1892
2011
|
content: string;
|
|
@@ -2019,7 +2138,7 @@ interface AgentPublicChatParams extends AgentChatParams {
|
|
|
2019
2138
|
triggerSubtype?: string;
|
|
2020
2139
|
triggerNodeId?: string;
|
|
2021
2140
|
}
|
|
2022
|
-
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser> {
|
|
2141
|
+
declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions> {
|
|
2023
2142
|
readonly agents: RagableBrowserAgentsClient;
|
|
2024
2143
|
readonly ai: RagableBrowserAiClient;
|
|
2025
2144
|
readonly auth: RagableBrowserAuthClient<AuthUser>;
|
|
@@ -2027,6 +2146,11 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
2027
2146
|
readonly db: RagableBrowserDatabaseClient<Database>;
|
|
2028
2147
|
readonly storage: RagableBrowserStorageClient;
|
|
2029
2148
|
readonly mail: RagableBrowserMailClient;
|
|
2149
|
+
/**
|
|
2150
|
+
* Backend edge functions — call a `/functions/<name>.ts` handler with
|
|
2151
|
+
* `client.functions.<name>(input)`. Runs server-side. See {@link FunctionInvoker}.
|
|
2152
|
+
*/
|
|
2153
|
+
readonly functions: FunctionInvoker<Functions>;
|
|
2030
2154
|
readonly transport: Transport;
|
|
2031
2155
|
private readonly _ragableAuth;
|
|
2032
2156
|
constructor(options: RagableBrowserClientOptions);
|
|
@@ -2034,7 +2158,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
|
|
|
2034
2158
|
from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
|
|
2035
2159
|
destroy(): void;
|
|
2036
2160
|
}
|
|
2037
|
-
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
2161
|
+
declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2038
2162
|
declare const createRagableBrowserClient: typeof createBrowserClient;
|
|
2039
2163
|
|
|
2040
2164
|
/**
|
|
@@ -2065,6 +2189,6 @@ declare function readSseStream(body: ReadableStream<Uint8Array>): AsyncGenerator
|
|
|
2065
2189
|
*/
|
|
2066
2190
|
declare function tryParsePartialJson(text: string): unknown | undefined;
|
|
2067
2191
|
|
|
2068
|
-
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
2192
|
+
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2069
2193
|
|
|
2070
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FinishReason, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
|
2194
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,7 @@ __export(index_exports, {
|
|
|
47
47
|
RagableBrowserAiClient: () => RagableBrowserAiClient,
|
|
48
48
|
RagableBrowserAuthClient: () => RagableBrowserAuthClient,
|
|
49
49
|
RagableBrowserDatabaseClient: () => RagableBrowserDatabaseClient,
|
|
50
|
+
RagableBrowserFunctionsClient: () => RagableBrowserFunctionsClient,
|
|
50
51
|
RagableBrowserMailClient: () => RagableBrowserMailClient,
|
|
51
52
|
RagableBrowserStorageClient: () => RagableBrowserStorageClient,
|
|
52
53
|
RagableError: () => RagableError,
|
|
@@ -3989,6 +3990,99 @@ var RagableBrowserMailClient = class {
|
|
|
3989
3990
|
return message;
|
|
3990
3991
|
}
|
|
3991
3992
|
};
|
|
3993
|
+
var RagableBrowserFunctionsClient = class {
|
|
3994
|
+
constructor(options, auth) {
|
|
3995
|
+
this.options = options;
|
|
3996
|
+
this.auth = auth;
|
|
3997
|
+
__publicField(this, "fetchImpl");
|
|
3998
|
+
this.fetchImpl = bindFetch(options.fetch);
|
|
3999
|
+
}
|
|
4000
|
+
requireWebsiteId() {
|
|
4001
|
+
const websiteId = this.options.websiteId?.trim();
|
|
4002
|
+
if (!websiteId) {
|
|
4003
|
+
throw new RagableError(
|
|
4004
|
+
"websiteId is required for functions. Use createWebsiteRagableClient()/createAppClient() or pass createBrowserClient({ websiteId, ... }).",
|
|
4005
|
+
400,
|
|
4006
|
+
{ code: "SDK_MISSING_WEBSITE_ID" }
|
|
4007
|
+
);
|
|
4008
|
+
}
|
|
4009
|
+
return websiteId;
|
|
4010
|
+
}
|
|
4011
|
+
toUrl(name) {
|
|
4012
|
+
const orgId = this.options.organizationId;
|
|
4013
|
+
const websiteId = this.requireWebsiteId();
|
|
4014
|
+
return `${normalizeBrowserApiBase()}/public/organizations/${orgId}/websites/${websiteId}/functions/${encodeURIComponent(
|
|
4015
|
+
name
|
|
4016
|
+
)}/invoke`;
|
|
4017
|
+
}
|
|
4018
|
+
/**
|
|
4019
|
+
* Best-effort end-user bearer, forwarded to the function as `context.auth.token`.
|
|
4020
|
+
* Functions are public, so this never throws — anonymous calls send no token.
|
|
4021
|
+
*/
|
|
4022
|
+
async getOptionalToken() {
|
|
4023
|
+
if (this.auth) {
|
|
4024
|
+
const token = await this.auth.getValidAccessToken().catch(() => null);
|
|
4025
|
+
if (token) return token;
|
|
4026
|
+
}
|
|
4027
|
+
const caller = await Promise.resolve(this.options.getAccessToken?.()).catch(
|
|
4028
|
+
() => null
|
|
4029
|
+
);
|
|
4030
|
+
if (typeof caller === "string" && caller.trim()) return caller.trim();
|
|
4031
|
+
const staticKey = this.options.dataStaticKey?.trim();
|
|
4032
|
+
if (staticKey) return staticKey;
|
|
4033
|
+
return null;
|
|
4034
|
+
}
|
|
4035
|
+
/**
|
|
4036
|
+
* Invoke a function by name. Prefer the typed `client.functions.<name>(input)`
|
|
4037
|
+
* accessors; use this when the name is dynamic.
|
|
4038
|
+
*/
|
|
4039
|
+
async invoke(name, input, options) {
|
|
4040
|
+
const fnName = String(name ?? "").trim();
|
|
4041
|
+
if (!fnName) {
|
|
4042
|
+
throw new RagableError(
|
|
4043
|
+
"functions.invoke requires a function name",
|
|
4044
|
+
400,
|
|
4045
|
+
{ code: "SDK_MISSING_FUNCTION_NAME" }
|
|
4046
|
+
);
|
|
4047
|
+
}
|
|
4048
|
+
const headers = new Headers(options?.headers ?? this.options.headers);
|
|
4049
|
+
headers.set("Content-Type", "application/json");
|
|
4050
|
+
const token = await this.getOptionalToken();
|
|
4051
|
+
if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
4052
|
+
const response = await this.fetchImpl(this.toUrl(fnName), {
|
|
4053
|
+
method: "POST",
|
|
4054
|
+
headers,
|
|
4055
|
+
body: JSON.stringify({ input: input ?? null }),
|
|
4056
|
+
...options?.signal ? { signal: options.signal } : {}
|
|
4057
|
+
});
|
|
4058
|
+
const payload = await parseMaybeJsonBody(response);
|
|
4059
|
+
if (!response.ok) {
|
|
4060
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
4061
|
+
throw new RagableError(message, response.status, payload);
|
|
4062
|
+
}
|
|
4063
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload) && "result" in payload) {
|
|
4064
|
+
return payload.result;
|
|
4065
|
+
}
|
|
4066
|
+
return payload;
|
|
4067
|
+
}
|
|
4068
|
+
/** Build the typed Proxy exposed as `client.functions`. */
|
|
4069
|
+
asInvoker() {
|
|
4070
|
+
const invoke = this.invoke.bind(this);
|
|
4071
|
+
return new Proxy(
|
|
4072
|
+
{},
|
|
4073
|
+
{
|
|
4074
|
+
get: (_target, prop) => {
|
|
4075
|
+
if (typeof prop !== "string") return void 0;
|
|
4076
|
+
if (prop === "then") return void 0;
|
|
4077
|
+
if (prop === "invoke") {
|
|
4078
|
+
return (name, input, options) => invoke(name, input, options);
|
|
4079
|
+
}
|
|
4080
|
+
return (input, options) => invoke(prop, input, options);
|
|
4081
|
+
}
|
|
4082
|
+
}
|
|
4083
|
+
);
|
|
4084
|
+
}
|
|
4085
|
+
};
|
|
3992
4086
|
var RagableBrowserAgentsClient = class {
|
|
3993
4087
|
constructor(options) {
|
|
3994
4088
|
this.options = options;
|
|
@@ -4316,6 +4410,11 @@ var RagableBrowser = class {
|
|
|
4316
4410
|
__publicField(this, "db");
|
|
4317
4411
|
__publicField(this, "storage");
|
|
4318
4412
|
__publicField(this, "mail");
|
|
4413
|
+
/**
|
|
4414
|
+
* Backend edge functions — call a `/functions/<name>.ts` handler with
|
|
4415
|
+
* `client.functions.<name>(input)`. Runs server-side. See {@link FunctionInvoker}.
|
|
4416
|
+
*/
|
|
4417
|
+
__publicField(this, "functions");
|
|
4319
4418
|
__publicField(this, "transport");
|
|
4320
4419
|
__publicField(this, "_ragableAuth");
|
|
4321
4420
|
/** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
|
|
@@ -4362,6 +4461,10 @@ var RagableBrowser = class {
|
|
|
4362
4461
|
this.db = this.database;
|
|
4363
4462
|
this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch));
|
|
4364
4463
|
this.mail = new RagableBrowserMailClient(options, this._ragableAuth);
|
|
4464
|
+
this.functions = new RagableBrowserFunctionsClient(
|
|
4465
|
+
options,
|
|
4466
|
+
this._ragableAuth
|
|
4467
|
+
).asInvoker();
|
|
4365
4468
|
}
|
|
4366
4469
|
destroy() {
|
|
4367
4470
|
this._ragableAuth?.destroy();
|
|
@@ -4403,6 +4506,7 @@ function createClient(options) {
|
|
|
4403
4506
|
RagableBrowserAiClient,
|
|
4404
4507
|
RagableBrowserAuthClient,
|
|
4405
4508
|
RagableBrowserDatabaseClient,
|
|
4509
|
+
RagableBrowserFunctionsClient,
|
|
4406
4510
|
RagableBrowserMailClient,
|
|
4407
4511
|
RagableBrowserStorageClient,
|
|
4408
4512
|
RagableError,
|