@ragable/sdk 0.6.20 → 0.6.22
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 +159 -10
- package/dist/index.d.ts +159 -10
- package/dist/index.js +230 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +224 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -313,6 +313,26 @@ type PostgrestResult<T> = {
|
|
|
313
313
|
data: null;
|
|
314
314
|
error: RagableError;
|
|
315
315
|
};
|
|
316
|
+
/** Discriminated result for easier TypeScript narrowing than `{ data, error }` after destructuring. */
|
|
317
|
+
type RagableResult<T, E = RagableError> = {
|
|
318
|
+
ok: true;
|
|
319
|
+
value: T;
|
|
320
|
+
} | {
|
|
321
|
+
ok: false;
|
|
322
|
+
error: E;
|
|
323
|
+
};
|
|
324
|
+
declare function toRagableResult<T>(r: PostgrestResult<T>): RagableResult<T>;
|
|
325
|
+
/**
|
|
326
|
+
* Narrows a {@link PostgrestResult} after an `if (result.error)` guard.
|
|
327
|
+
* Prefer checking `result.error` on the result object (not destructured `{ data, error }`)
|
|
328
|
+
* so TypeScript narrows `data` automatically; use this when you need a throw or assertion.
|
|
329
|
+
*/
|
|
330
|
+
declare function assertPostgrestSuccess<T>(r: PostgrestResult<T>): asserts r is {
|
|
331
|
+
data: T;
|
|
332
|
+
error: null;
|
|
333
|
+
};
|
|
334
|
+
/** Returns `data` or throws `RagableError` / the failure case. */
|
|
335
|
+
declare function unwrapPostgrest<T>(r: PostgrestResult<T>): T;
|
|
316
336
|
declare function asPostgrestResponse<T>(fn: () => Promise<T>): Promise<PostgrestResult<T>>;
|
|
317
337
|
type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike" | "is" | "in";
|
|
318
338
|
interface Filter {
|
|
@@ -836,6 +856,7 @@ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
|
836
856
|
declare function effectiveDataAuth(options: RagableBrowserClientOptions): BrowserDataAuthMode;
|
|
837
857
|
interface RagableBrowserClientOptions {
|
|
838
858
|
organizationId: string;
|
|
859
|
+
websiteId?: string;
|
|
839
860
|
authGroupId?: string;
|
|
840
861
|
databaseInstanceId?: string;
|
|
841
862
|
/** When omitted, inferred from static keys — see {@link effectiveDataAuth}. */
|
|
@@ -991,7 +1012,34 @@ interface BrowserCollectionDefinition {
|
|
|
991
1012
|
createdAt: string;
|
|
992
1013
|
updatedAt: string;
|
|
993
1014
|
}
|
|
994
|
-
|
|
1015
|
+
/**
|
|
1016
|
+
* Prisma-style operator object for a single field (server-supported ops).
|
|
1017
|
+
* Typed loosely so schema-specific refinements can be added in app code.
|
|
1018
|
+
*/
|
|
1019
|
+
type WhereOperatorObject = {
|
|
1020
|
+
eq?: unknown;
|
|
1021
|
+
neq?: unknown;
|
|
1022
|
+
gt?: number;
|
|
1023
|
+
gte?: number;
|
|
1024
|
+
lt?: number;
|
|
1025
|
+
lte?: number;
|
|
1026
|
+
in?: unknown;
|
|
1027
|
+
contains?: unknown;
|
|
1028
|
+
};
|
|
1029
|
+
/**
|
|
1030
|
+
* `where` filters: equality on values, or per-field operator objects.
|
|
1031
|
+
* Use `id`, `createdAt`, `updatedAt` to match the record envelope (DB columns), not `data` JSON
|
|
1032
|
+
* (unless you also have those keys in your JSON — prefer envelope keys for `id`).
|
|
1033
|
+
*/
|
|
1034
|
+
type WhereInput<Row extends Record<string, unknown>> = {
|
|
1035
|
+
[K in keyof Row]?: Row[K] | WhereOperatorObject | null;
|
|
1036
|
+
} & {
|
|
1037
|
+
id?: string | WhereOperatorObject;
|
|
1038
|
+
createdAt?: string | WhereOperatorObject;
|
|
1039
|
+
updatedAt?: string | WhereOperatorObject;
|
|
1040
|
+
};
|
|
1041
|
+
/** @deprecated Use {@link WhereInput} — same shape. */
|
|
1042
|
+
type CollectionWhere<Row extends Record<string, unknown>> = WhereInput<Row>;
|
|
995
1043
|
type CollectionFilter<Row extends Record<string, unknown>> = {
|
|
996
1044
|
[Field in Extract<keyof Row, string>]: {
|
|
997
1045
|
field: Field;
|
|
@@ -999,8 +1047,22 @@ type CollectionFilter<Row extends Record<string, unknown>> = {
|
|
|
999
1047
|
value: Row[Field];
|
|
1000
1048
|
};
|
|
1001
1049
|
}[Extract<keyof Row, string>];
|
|
1050
|
+
type CollectionReturnMode = "envelope" | "flat";
|
|
1051
|
+
/**
|
|
1052
|
+
* One row: JSON fields at the top level, envelope fields under `meta`
|
|
1053
|
+
* (when using {@link BrowserCollectionApi.findMany} with `return: "flat"`).
|
|
1054
|
+
*/
|
|
1055
|
+
type CollectionRowWithMeta<Row extends Record<string, unknown> = Record<string, unknown>> = Row & {
|
|
1056
|
+
meta: {
|
|
1057
|
+
id: string;
|
|
1058
|
+
createdAt: string;
|
|
1059
|
+
updatedAt: string;
|
|
1060
|
+
};
|
|
1061
|
+
};
|
|
1062
|
+
declare function collectionRecordToRowWithMeta<Row extends Record<string, unknown>>(record: BrowserCollectionRecord<Row>): CollectionRowWithMeta<Row>;
|
|
1063
|
+
declare function collectionRecordsToRowWithMeta<Row extends Record<string, unknown>>(records: BrowserCollectionRecord<Row>[]): CollectionRowWithMeta<Row>[];
|
|
1002
1064
|
type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<string, unknown>> = {
|
|
1003
|
-
where?:
|
|
1065
|
+
where?: WhereInput<Row>;
|
|
1004
1066
|
filters?: Array<{
|
|
1005
1067
|
field: Extract<keyof Row, string> | (string & {});
|
|
1006
1068
|
op?: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "contains";
|
|
@@ -1008,24 +1070,69 @@ type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<st
|
|
|
1008
1070
|
} | CollectionFilter<Row>>;
|
|
1009
1071
|
limit?: number;
|
|
1010
1072
|
offset?: number;
|
|
1011
|
-
orderBy?: Extract<keyof Row, string> | (string & {});
|
|
1073
|
+
orderBy?: Extract<keyof Row, string> | "id" | "createdAt" | "updatedAt" | (string & {});
|
|
1012
1074
|
orderDirection?: "asc" | "desc";
|
|
1075
|
+
/**
|
|
1076
|
+
* - `envelope` (default): `Array<{ id, data, createdAt, updatedAt }>`
|
|
1077
|
+
* - `flat`: {@link CollectionRowWithMeta} — row fields at top level + `meta` for `id` / timestamps
|
|
1078
|
+
*/
|
|
1079
|
+
return?: CollectionReturnMode;
|
|
1013
1080
|
};
|
|
1081
|
+
type CollectionRowData<Row extends Record<string, unknown> = Record<string, unknown>> = BrowserCollectionRowData<Row>;
|
|
1082
|
+
type RowD<Row extends Record<string, unknown>> = BrowserCollectionRowData<Row>;
|
|
1014
1083
|
declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<string, unknown>, Insert extends Record<string, unknown> = Row, Update extends Record<string, unknown> = Partial<Row>> {
|
|
1015
1084
|
private readonly database;
|
|
1016
1085
|
private readonly name;
|
|
1017
1086
|
private readonly databaseInstanceId?;
|
|
1018
1087
|
constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1088
|
+
private normalizeFindArgs;
|
|
1089
|
+
private requestFind;
|
|
1090
|
+
/**
|
|
1091
|
+
* Query collection rows. Prefer this over the deprecated `find` alias.
|
|
1092
|
+
* Use `return: "flat"` to get {@link CollectionRowWithMeta} without nested `.data`.
|
|
1093
|
+
*/
|
|
1094
|
+
findMany: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
|
|
1095
|
+
/**
|
|
1096
|
+
* @deprecated Use {@link BrowserCollectionApi.findMany} — same behavior.
|
|
1097
|
+
*/
|
|
1098
|
+
find: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
|
|
1099
|
+
/**
|
|
1100
|
+
* At most one row, `data` is the record or `null` if none match (not an error).
|
|
1101
|
+
*/
|
|
1102
|
+
findFirst: (whereOrParams?: WhereInput<RowD<Row>> | Omit<BrowserCollectionFindParams<RowD<Row>>, "return">) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Lookup by primary key `id` (envelope). Equivalent to
|
|
1105
|
+
* `findFirst({ where: { id }, limit: 1 })` with a typed `where.id`.
|
|
1106
|
+
*/
|
|
1107
|
+
findUnique: (args: {
|
|
1108
|
+
where: {
|
|
1109
|
+
id: string;
|
|
1110
|
+
} & Partial<WhereInput<RowD<Row>>>;
|
|
1111
|
+
}) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
|
|
1112
|
+
insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>>>;
|
|
1113
|
+
/**
|
|
1114
|
+
* Update rows matching `where` (JSON fields, plus envelope `id` / `createdAt` / `updatedAt`).
|
|
1115
|
+
*/
|
|
1116
|
+
update: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
|
|
1022
1117
|
limit?: number;
|
|
1023
|
-
}) => Promise<PostgrestResult<BrowserCollectionRecord<
|
|
1024
|
-
|
|
1118
|
+
}) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[]>>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Like {@link BrowserCollectionApi.update} but the success payload includes
|
|
1121
|
+
* `meta.count` (number of rows returned from the update, bounded by `limit`).
|
|
1122
|
+
*/
|
|
1123
|
+
updateMany: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
|
|
1124
|
+
limit?: number;
|
|
1125
|
+
}) => Promise<PostgrestResult<{
|
|
1126
|
+
records: BrowserCollectionRecord<RowD<Row>>[];
|
|
1127
|
+
meta: {
|
|
1128
|
+
count: number;
|
|
1129
|
+
};
|
|
1130
|
+
}>>;
|
|
1131
|
+
delete: (where: WhereInput<RowD<Row>>, options?: {
|
|
1025
1132
|
limit?: number;
|
|
1026
1133
|
}) => Promise<PostgrestResult<{
|
|
1027
1134
|
deleted: number;
|
|
1028
|
-
records: BrowserCollectionRecord<
|
|
1135
|
+
records: BrowserCollectionRecord<RowD<Row>>[];
|
|
1029
1136
|
}>>;
|
|
1030
1137
|
}
|
|
1031
1138
|
type BrowserCollections<Database extends RagableDatabase = DefaultRagableDatabase> = [keyof Database["public"]["Tables"]] extends [never] ? Record<string, BrowserCollectionApi<Record<string, unknown>>> : {
|
|
@@ -1141,12 +1248,54 @@ interface BrowserRealtimeSubscription {
|
|
|
1141
1248
|
unsubscribe: () => void;
|
|
1142
1249
|
readonly status: BrowserRealtimeStatus;
|
|
1143
1250
|
}
|
|
1251
|
+
interface AgentConversationMessage {
|
|
1252
|
+
role: "user" | "assistant";
|
|
1253
|
+
content: string;
|
|
1254
|
+
file_urls?: string[];
|
|
1255
|
+
}
|
|
1256
|
+
interface AgentConversation {
|
|
1257
|
+
id: string;
|
|
1258
|
+
agent_name: string;
|
|
1259
|
+
agentName: string;
|
|
1260
|
+
title: string | null;
|
|
1261
|
+
metadata: unknown;
|
|
1262
|
+
messages: AgentConversationMessage[];
|
|
1263
|
+
createdAt: string;
|
|
1264
|
+
updatedAt: string;
|
|
1265
|
+
}
|
|
1266
|
+
interface AgentConversationSubscription {
|
|
1267
|
+
unsubscribe: () => void;
|
|
1268
|
+
}
|
|
1144
1269
|
declare class RagableBrowserAgentsClient {
|
|
1145
1270
|
private readonly options;
|
|
1146
1271
|
private readonly fetchImpl;
|
|
1147
1272
|
constructor(options: RagableBrowserClientOptions);
|
|
1148
1273
|
private toUrl;
|
|
1274
|
+
private requireWebsiteId;
|
|
1275
|
+
private websiteAgentPath;
|
|
1276
|
+
private requestJson;
|
|
1277
|
+
/** @deprecated Prefer `chatStreamByName(agentName, params)` for project-local `/agents/*.json` agents. */
|
|
1149
1278
|
chatStream(agentId: string, params: AgentPublicChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
1279
|
+
chatStreamByName(agentName: string, params: AgentChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
1280
|
+
createConversation(params: {
|
|
1281
|
+
agent_name?: string;
|
|
1282
|
+
agentName?: string;
|
|
1283
|
+
title?: string | null;
|
|
1284
|
+
metadata?: unknown;
|
|
1285
|
+
}): Promise<AgentConversation>;
|
|
1286
|
+
listConversations(params?: {
|
|
1287
|
+
agent_name?: string;
|
|
1288
|
+
agentName?: string;
|
|
1289
|
+
}): Promise<AgentConversation[]>;
|
|
1290
|
+
getConversation(conversationId: string): Promise<AgentConversation>;
|
|
1291
|
+
updateConversation(conversationId: string, data: {
|
|
1292
|
+
title?: string | null;
|
|
1293
|
+
metadata?: unknown;
|
|
1294
|
+
}): Promise<AgentConversation>;
|
|
1295
|
+
addMessage(conversationOrId: AgentConversation | string, message: AgentConversationMessage): Promise<AgentConversation>;
|
|
1296
|
+
subscribeToConversation(conversationId: string, callback: (conversation: AgentConversation) => void, options?: {
|
|
1297
|
+
intervalMs?: number;
|
|
1298
|
+
}): AgentConversationSubscription;
|
|
1150
1299
|
}
|
|
1151
1300
|
interface AgentPublicChatParams extends AgentChatParams {
|
|
1152
1301
|
triggerSubtype?: string;
|
|
@@ -1242,4 +1391,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
|
|
|
1242
1391
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1243
1392
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
1244
1393
|
|
|
1245
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, 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, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
|
1394
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, 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, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream, toRagableResult, unwrapPostgrest };
|
package/dist/index.d.ts
CHANGED
|
@@ -313,6 +313,26 @@ type PostgrestResult<T> = {
|
|
|
313
313
|
data: null;
|
|
314
314
|
error: RagableError;
|
|
315
315
|
};
|
|
316
|
+
/** Discriminated result for easier TypeScript narrowing than `{ data, error }` after destructuring. */
|
|
317
|
+
type RagableResult<T, E = RagableError> = {
|
|
318
|
+
ok: true;
|
|
319
|
+
value: T;
|
|
320
|
+
} | {
|
|
321
|
+
ok: false;
|
|
322
|
+
error: E;
|
|
323
|
+
};
|
|
324
|
+
declare function toRagableResult<T>(r: PostgrestResult<T>): RagableResult<T>;
|
|
325
|
+
/**
|
|
326
|
+
* Narrows a {@link PostgrestResult} after an `if (result.error)` guard.
|
|
327
|
+
* Prefer checking `result.error` on the result object (not destructured `{ data, error }`)
|
|
328
|
+
* so TypeScript narrows `data` automatically; use this when you need a throw or assertion.
|
|
329
|
+
*/
|
|
330
|
+
declare function assertPostgrestSuccess<T>(r: PostgrestResult<T>): asserts r is {
|
|
331
|
+
data: T;
|
|
332
|
+
error: null;
|
|
333
|
+
};
|
|
334
|
+
/** Returns `data` or throws `RagableError` / the failure case. */
|
|
335
|
+
declare function unwrapPostgrest<T>(r: PostgrestResult<T>): T;
|
|
316
336
|
declare function asPostgrestResponse<T>(fn: () => Promise<T>): Promise<PostgrestResult<T>>;
|
|
317
337
|
type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike" | "is" | "in";
|
|
318
338
|
interface Filter {
|
|
@@ -836,6 +856,7 @@ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
|
836
856
|
declare function effectiveDataAuth(options: RagableBrowserClientOptions): BrowserDataAuthMode;
|
|
837
857
|
interface RagableBrowserClientOptions {
|
|
838
858
|
organizationId: string;
|
|
859
|
+
websiteId?: string;
|
|
839
860
|
authGroupId?: string;
|
|
840
861
|
databaseInstanceId?: string;
|
|
841
862
|
/** When omitted, inferred from static keys — see {@link effectiveDataAuth}. */
|
|
@@ -991,7 +1012,34 @@ interface BrowserCollectionDefinition {
|
|
|
991
1012
|
createdAt: string;
|
|
992
1013
|
updatedAt: string;
|
|
993
1014
|
}
|
|
994
|
-
|
|
1015
|
+
/**
|
|
1016
|
+
* Prisma-style operator object for a single field (server-supported ops).
|
|
1017
|
+
* Typed loosely so schema-specific refinements can be added in app code.
|
|
1018
|
+
*/
|
|
1019
|
+
type WhereOperatorObject = {
|
|
1020
|
+
eq?: unknown;
|
|
1021
|
+
neq?: unknown;
|
|
1022
|
+
gt?: number;
|
|
1023
|
+
gte?: number;
|
|
1024
|
+
lt?: number;
|
|
1025
|
+
lte?: number;
|
|
1026
|
+
in?: unknown;
|
|
1027
|
+
contains?: unknown;
|
|
1028
|
+
};
|
|
1029
|
+
/**
|
|
1030
|
+
* `where` filters: equality on values, or per-field operator objects.
|
|
1031
|
+
* Use `id`, `createdAt`, `updatedAt` to match the record envelope (DB columns), not `data` JSON
|
|
1032
|
+
* (unless you also have those keys in your JSON — prefer envelope keys for `id`).
|
|
1033
|
+
*/
|
|
1034
|
+
type WhereInput<Row extends Record<string, unknown>> = {
|
|
1035
|
+
[K in keyof Row]?: Row[K] | WhereOperatorObject | null;
|
|
1036
|
+
} & {
|
|
1037
|
+
id?: string | WhereOperatorObject;
|
|
1038
|
+
createdAt?: string | WhereOperatorObject;
|
|
1039
|
+
updatedAt?: string | WhereOperatorObject;
|
|
1040
|
+
};
|
|
1041
|
+
/** @deprecated Use {@link WhereInput} — same shape. */
|
|
1042
|
+
type CollectionWhere<Row extends Record<string, unknown>> = WhereInput<Row>;
|
|
995
1043
|
type CollectionFilter<Row extends Record<string, unknown>> = {
|
|
996
1044
|
[Field in Extract<keyof Row, string>]: {
|
|
997
1045
|
field: Field;
|
|
@@ -999,8 +1047,22 @@ type CollectionFilter<Row extends Record<string, unknown>> = {
|
|
|
999
1047
|
value: Row[Field];
|
|
1000
1048
|
};
|
|
1001
1049
|
}[Extract<keyof Row, string>];
|
|
1050
|
+
type CollectionReturnMode = "envelope" | "flat";
|
|
1051
|
+
/**
|
|
1052
|
+
* One row: JSON fields at the top level, envelope fields under `meta`
|
|
1053
|
+
* (when using {@link BrowserCollectionApi.findMany} with `return: "flat"`).
|
|
1054
|
+
*/
|
|
1055
|
+
type CollectionRowWithMeta<Row extends Record<string, unknown> = Record<string, unknown>> = Row & {
|
|
1056
|
+
meta: {
|
|
1057
|
+
id: string;
|
|
1058
|
+
createdAt: string;
|
|
1059
|
+
updatedAt: string;
|
|
1060
|
+
};
|
|
1061
|
+
};
|
|
1062
|
+
declare function collectionRecordToRowWithMeta<Row extends Record<string, unknown>>(record: BrowserCollectionRecord<Row>): CollectionRowWithMeta<Row>;
|
|
1063
|
+
declare function collectionRecordsToRowWithMeta<Row extends Record<string, unknown>>(records: BrowserCollectionRecord<Row>[]): CollectionRowWithMeta<Row>[];
|
|
1002
1064
|
type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<string, unknown>> = {
|
|
1003
|
-
where?:
|
|
1065
|
+
where?: WhereInput<Row>;
|
|
1004
1066
|
filters?: Array<{
|
|
1005
1067
|
field: Extract<keyof Row, string> | (string & {});
|
|
1006
1068
|
op?: "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "contains";
|
|
@@ -1008,24 +1070,69 @@ type BrowserCollectionFindParams<Row extends Record<string, unknown> = Record<st
|
|
|
1008
1070
|
} | CollectionFilter<Row>>;
|
|
1009
1071
|
limit?: number;
|
|
1010
1072
|
offset?: number;
|
|
1011
|
-
orderBy?: Extract<keyof Row, string> | (string & {});
|
|
1073
|
+
orderBy?: Extract<keyof Row, string> | "id" | "createdAt" | "updatedAt" | (string & {});
|
|
1012
1074
|
orderDirection?: "asc" | "desc";
|
|
1075
|
+
/**
|
|
1076
|
+
* - `envelope` (default): `Array<{ id, data, createdAt, updatedAt }>`
|
|
1077
|
+
* - `flat`: {@link CollectionRowWithMeta} — row fields at top level + `meta` for `id` / timestamps
|
|
1078
|
+
*/
|
|
1079
|
+
return?: CollectionReturnMode;
|
|
1013
1080
|
};
|
|
1081
|
+
type CollectionRowData<Row extends Record<string, unknown> = Record<string, unknown>> = BrowserCollectionRowData<Row>;
|
|
1082
|
+
type RowD<Row extends Record<string, unknown>> = BrowserCollectionRowData<Row>;
|
|
1014
1083
|
declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<string, unknown>, Insert extends Record<string, unknown> = Row, Update extends Record<string, unknown> = Partial<Row>> {
|
|
1015
1084
|
private readonly database;
|
|
1016
1085
|
private readonly name;
|
|
1017
1086
|
private readonly databaseInstanceId?;
|
|
1018
1087
|
constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1088
|
+
private normalizeFindArgs;
|
|
1089
|
+
private requestFind;
|
|
1090
|
+
/**
|
|
1091
|
+
* Query collection rows. Prefer this over the deprecated `find` alias.
|
|
1092
|
+
* Use `return: "flat"` to get {@link CollectionRowWithMeta} without nested `.data`.
|
|
1093
|
+
*/
|
|
1094
|
+
findMany: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
|
|
1095
|
+
/**
|
|
1096
|
+
* @deprecated Use {@link BrowserCollectionApi.findMany} — same behavior.
|
|
1097
|
+
*/
|
|
1098
|
+
find: (whereOrParams?: WhereInput<RowD<Row>> | BrowserCollectionFindParams<RowD<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[] | CollectionRowWithMeta<RowD<Row>>[]>>;
|
|
1099
|
+
/**
|
|
1100
|
+
* At most one row, `data` is the record or `null` if none match (not an error).
|
|
1101
|
+
*/
|
|
1102
|
+
findFirst: (whereOrParams?: WhereInput<RowD<Row>> | Omit<BrowserCollectionFindParams<RowD<Row>>, "return">) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Lookup by primary key `id` (envelope). Equivalent to
|
|
1105
|
+
* `findFirst({ where: { id }, limit: 1 })` with a typed `where.id`.
|
|
1106
|
+
*/
|
|
1107
|
+
findUnique: (args: {
|
|
1108
|
+
where: {
|
|
1109
|
+
id: string;
|
|
1110
|
+
} & Partial<WhereInput<RowD<Row>>>;
|
|
1111
|
+
}) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>> | null>>;
|
|
1112
|
+
insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>>>;
|
|
1113
|
+
/**
|
|
1114
|
+
* Update rows matching `where` (JSON fields, plus envelope `id` / `createdAt` / `updatedAt`).
|
|
1115
|
+
*/
|
|
1116
|
+
update: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
|
|
1022
1117
|
limit?: number;
|
|
1023
|
-
}) => Promise<PostgrestResult<BrowserCollectionRecord<
|
|
1024
|
-
|
|
1118
|
+
}) => Promise<PostgrestResult<BrowserCollectionRecord<RowD<Row>>[]>>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Like {@link BrowserCollectionApi.update} but the success payload includes
|
|
1121
|
+
* `meta.count` (number of rows returned from the update, bounded by `limit`).
|
|
1122
|
+
*/
|
|
1123
|
+
updateMany: (where: WhereInput<RowD<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
|
|
1124
|
+
limit?: number;
|
|
1125
|
+
}) => Promise<PostgrestResult<{
|
|
1126
|
+
records: BrowserCollectionRecord<RowD<Row>>[];
|
|
1127
|
+
meta: {
|
|
1128
|
+
count: number;
|
|
1129
|
+
};
|
|
1130
|
+
}>>;
|
|
1131
|
+
delete: (where: WhereInput<RowD<Row>>, options?: {
|
|
1025
1132
|
limit?: number;
|
|
1026
1133
|
}) => Promise<PostgrestResult<{
|
|
1027
1134
|
deleted: number;
|
|
1028
|
-
records: BrowserCollectionRecord<
|
|
1135
|
+
records: BrowserCollectionRecord<RowD<Row>>[];
|
|
1029
1136
|
}>>;
|
|
1030
1137
|
}
|
|
1031
1138
|
type BrowserCollections<Database extends RagableDatabase = DefaultRagableDatabase> = [keyof Database["public"]["Tables"]] extends [never] ? Record<string, BrowserCollectionApi<Record<string, unknown>>> : {
|
|
@@ -1141,12 +1248,54 @@ interface BrowserRealtimeSubscription {
|
|
|
1141
1248
|
unsubscribe: () => void;
|
|
1142
1249
|
readonly status: BrowserRealtimeStatus;
|
|
1143
1250
|
}
|
|
1251
|
+
interface AgentConversationMessage {
|
|
1252
|
+
role: "user" | "assistant";
|
|
1253
|
+
content: string;
|
|
1254
|
+
file_urls?: string[];
|
|
1255
|
+
}
|
|
1256
|
+
interface AgentConversation {
|
|
1257
|
+
id: string;
|
|
1258
|
+
agent_name: string;
|
|
1259
|
+
agentName: string;
|
|
1260
|
+
title: string | null;
|
|
1261
|
+
metadata: unknown;
|
|
1262
|
+
messages: AgentConversationMessage[];
|
|
1263
|
+
createdAt: string;
|
|
1264
|
+
updatedAt: string;
|
|
1265
|
+
}
|
|
1266
|
+
interface AgentConversationSubscription {
|
|
1267
|
+
unsubscribe: () => void;
|
|
1268
|
+
}
|
|
1144
1269
|
declare class RagableBrowserAgentsClient {
|
|
1145
1270
|
private readonly options;
|
|
1146
1271
|
private readonly fetchImpl;
|
|
1147
1272
|
constructor(options: RagableBrowserClientOptions);
|
|
1148
1273
|
private toUrl;
|
|
1274
|
+
private requireWebsiteId;
|
|
1275
|
+
private websiteAgentPath;
|
|
1276
|
+
private requestJson;
|
|
1277
|
+
/** @deprecated Prefer `chatStreamByName(agentName, params)` for project-local `/agents/*.json` agents. */
|
|
1149
1278
|
chatStream(agentId: string, params: AgentPublicChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
1279
|
+
chatStreamByName(agentName: string, params: AgentChatParams): AsyncGenerator<AgentStreamEvent, void, undefined>;
|
|
1280
|
+
createConversation(params: {
|
|
1281
|
+
agent_name?: string;
|
|
1282
|
+
agentName?: string;
|
|
1283
|
+
title?: string | null;
|
|
1284
|
+
metadata?: unknown;
|
|
1285
|
+
}): Promise<AgentConversation>;
|
|
1286
|
+
listConversations(params?: {
|
|
1287
|
+
agent_name?: string;
|
|
1288
|
+
agentName?: string;
|
|
1289
|
+
}): Promise<AgentConversation[]>;
|
|
1290
|
+
getConversation(conversationId: string): Promise<AgentConversation>;
|
|
1291
|
+
updateConversation(conversationId: string, data: {
|
|
1292
|
+
title?: string | null;
|
|
1293
|
+
metadata?: unknown;
|
|
1294
|
+
}): Promise<AgentConversation>;
|
|
1295
|
+
addMessage(conversationOrId: AgentConversation | string, message: AgentConversationMessage): Promise<AgentConversation>;
|
|
1296
|
+
subscribeToConversation(conversationId: string, callback: (conversation: AgentConversation) => void, options?: {
|
|
1297
|
+
intervalMs?: number;
|
|
1298
|
+
}): AgentConversationSubscription;
|
|
1150
1299
|
}
|
|
1151
1300
|
interface AgentPublicChatParams extends AgentChatParams {
|
|
1152
1301
|
triggerSubtype?: string;
|
|
@@ -1242,4 +1391,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
|
|
|
1242
1391
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1243
1392
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
1244
1393
|
|
|
1245
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, 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, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
|
1394
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, 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, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream, toRagableResult, unwrapPostgrest };
|