@ragable/sdk 0.6.1 → 0.6.3

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 CHANGED
@@ -100,7 +100,11 @@ declare class RagableError extends RagableSdkError {
100
100
  readonly details: string | undefined;
101
101
  constructor(message: string, status: number, body: unknown);
102
102
  toJSON(): Record<string, unknown>;
103
+ /** Stable string for logs — avoids `{}` when coercing or stringifying. */
104
+ toString(): string;
103
105
  }
106
+ /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
107
+ declare function formatSdkError(err: unknown): string;
104
108
  declare class RagableNetworkError extends RagableSdkError {
105
109
  readonly __type: "RagableNetworkError";
106
110
  readonly cause: unknown;
@@ -484,7 +488,7 @@ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagabl
484
488
  private readonly table;
485
489
  constructor(pgFetch: PostgRESTFetch, databaseInstanceId: string, table: TableName extends string ? string : string);
486
490
  select(columns?: string): PostgrestSelectBuilder<TableRow<Database, TableName>, Database, TableName>;
487
- insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
491
+ insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], ...rest: unknown[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
488
492
  update(patch: TableUpdatePatch<Database, TableName>): PostgrestUpdateRootBuilder<TableRow<Database, TableName>, Database, TableName>;
489
493
  delete(): PostgrestDeleteRootBuilder<TableRow<Database, TableName>, Database, TableName>;
490
494
  upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
@@ -863,11 +867,17 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
863
867
  truncated: boolean;
864
868
  rows: Row[];
865
869
  }
866
- declare class RagableBrowserDatabaseClient<_Schema extends RagableDatabase = DefaultRagableDatabase> {
870
+ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
867
871
  private readonly options;
868
872
  private readonly ragableAuth;
873
+ private readonly postgrestFrom?;
869
874
  private readonly fetchImpl;
870
- constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
875
+ constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null, postgrestFrom?: (<T extends RagableTableNames<Database>>(table: T, databaseInstanceId?: string) => PostgrestTableApi<Database, T>) | undefined);
876
+ /**
877
+ * PostgREST fluent API — same as `client.from('table')`.
878
+ * Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
879
+ */
880
+ from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
871
881
  private toUrl;
872
882
  query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
873
883
  private baseHeaders;
@@ -973,4 +983,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
973
983
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
974
984
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
975
985
 
976
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, 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, extractErrorMessage, formatRetrievalContext, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
986
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, 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, extractErrorMessage, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.d.ts CHANGED
@@ -100,7 +100,11 @@ declare class RagableError extends RagableSdkError {
100
100
  readonly details: string | undefined;
101
101
  constructor(message: string, status: number, body: unknown);
102
102
  toJSON(): Record<string, unknown>;
103
+ /** Stable string for logs — avoids `{}` when coercing or stringifying. */
104
+ toString(): string;
103
105
  }
106
+ /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
107
+ declare function formatSdkError(err: unknown): string;
104
108
  declare class RagableNetworkError extends RagableSdkError {
105
109
  readonly __type: "RagableNetworkError";
106
110
  readonly cause: unknown;
@@ -484,7 +488,7 @@ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagabl
484
488
  private readonly table;
485
489
  constructor(pgFetch: PostgRESTFetch, databaseInstanceId: string, table: TableName extends string ? string : string);
486
490
  select(columns?: string): PostgrestSelectBuilder<TableRow<Database, TableName>, Database, TableName>;
487
- insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
491
+ insert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], ...rest: unknown[]): PostgrestInsertRootBuilder<TableRow<Database, TableName>>;
488
492
  update(patch: TableUpdatePatch<Database, TableName>): PostgrestUpdateRootBuilder<TableRow<Database, TableName>, Database, TableName>;
489
493
  delete(): PostgrestDeleteRootBuilder<TableRow<Database, TableName>, Database, TableName>;
490
494
  upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
@@ -863,11 +867,17 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
863
867
  truncated: boolean;
864
868
  rows: Row[];
865
869
  }
866
- declare class RagableBrowserDatabaseClient<_Schema extends RagableDatabase = DefaultRagableDatabase> {
870
+ declare class RagableBrowserDatabaseClient<Database extends RagableDatabase = DefaultRagableDatabase> {
867
871
  private readonly options;
868
872
  private readonly ragableAuth;
873
+ private readonly postgrestFrom?;
869
874
  private readonly fetchImpl;
870
- constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null);
875
+ constructor(options: RagableBrowserClientOptions, ragableAuth?: RagableAuth | null, postgrestFrom?: (<T extends RagableTableNames<Database>>(table: T, databaseInstanceId?: string) => PostgrestTableApi<Database, T>) | undefined);
876
+ /**
877
+ * PostgREST fluent API — same as `client.from('table')`.
878
+ * Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
879
+ */
880
+ from<TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string): PostgrestTableApi<Database, TableName>;
871
881
  private toUrl;
872
882
  query<Row extends Record<string, unknown> = Record<string, unknown>>(params: BrowserSqlQueryParams): Promise<BrowserSqlQueryResult<Row>>;
873
883
  private baseHeaders;
@@ -973,4 +983,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
973
983
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
974
984
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
975
985
 
976
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, 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, extractErrorMessage, formatRetrievalContext, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
986
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, 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, extractErrorMessage, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.js CHANGED
@@ -63,6 +63,7 @@ __export(index_exports, {
63
63
  detectStorage: () => detectStorage,
64
64
  extractErrorMessage: () => extractErrorMessage,
65
65
  formatRetrievalContext: () => formatRetrievalContext,
66
+ formatSdkError: () => formatSdkError,
66
67
  generateIdempotencyKey: () => generateIdempotencyKey,
67
68
  normalizeBrowserApiBase: () => normalizeBrowserApiBase,
68
69
  parseSseDataLine: () => parseSseDataLine,
@@ -114,7 +115,34 @@ var RagableError = class extends RagableSdkError {
114
115
  details: this.details
115
116
  };
116
117
  }
118
+ /** Stable string for logs — avoids `{}` when coercing or stringifying. */
119
+ toString() {
120
+ const bits = [`${this.name}: ${this.message}`];
121
+ if (this.status) bits.push(`status=${this.status}`);
122
+ if (this.code) bits.push(`code=${this.code}`);
123
+ return bits.join(" \xB7 ");
124
+ }
117
125
  };
126
+ function formatSdkError(err) {
127
+ if (err instanceof RagableError) {
128
+ return `${err.message} (HTTP ${err.status}${err.code ? `, ${err.code}` : ""})`;
129
+ }
130
+ if (err instanceof RagableSdkError) {
131
+ return err.message;
132
+ }
133
+ if (err instanceof Error) {
134
+ return err.message || err.name;
135
+ }
136
+ if (typeof err === "string") return err;
137
+ if (err && typeof err === "object") {
138
+ try {
139
+ const s = JSON.stringify(err);
140
+ if (s !== "{}") return s;
141
+ } catch {
142
+ }
143
+ }
144
+ return String(err);
145
+ }
118
146
  var RagableNetworkError = class extends RagableSdkError {
119
147
  constructor(message, cause) {
120
148
  super(message);
@@ -1445,7 +1473,14 @@ var PostgrestTableApi = class {
1445
1473
  columns
1446
1474
  );
1447
1475
  }
1448
- insert(values) {
1476
+ insert(values, ...rest) {
1477
+ if (rest.length > 0) {
1478
+ throw new RagableError(
1479
+ ".insert() accepts only one argument: the row object or an array of rows. Do not pass readOnly, options, or a second object \u2014 those apply only to database.query({ sql, readOnly }). PostgREST inserts are writes by default.",
1480
+ 400,
1481
+ { code: "SDK_INSERT_EXTRA_ARGS" }
1482
+ );
1483
+ }
1449
1484
  const rows = Array.isArray(values) ? values : [values];
1450
1485
  return new PostgrestInsertRootBuilder(
1451
1486
  this.pgFetch,
@@ -2163,12 +2198,27 @@ var RagableBrowserAuthClient = class {
2163
2198
  }
2164
2199
  };
2165
2200
  var RagableBrowserDatabaseClient = class {
2166
- constructor(options, ragableAuth = null) {
2201
+ constructor(options, ragableAuth = null, postgrestFrom) {
2167
2202
  this.options = options;
2168
2203
  this.ragableAuth = ragableAuth;
2204
+ this.postgrestFrom = postgrestFrom;
2169
2205
  __publicField(this, "fetchImpl");
2170
2206
  this.fetchImpl = bindFetch(options.fetch);
2171
2207
  }
2208
+ /**
2209
+ * PostgREST fluent API — same as `client.from('table')`.
2210
+ * Use either the root client or `database` for Supabase-style table access; `database.query()` is raw SQL only.
2211
+ */
2212
+ from(table, databaseInstanceId) {
2213
+ if (!this.postgrestFrom) {
2214
+ throw new RagableError(
2215
+ "database.from() is only available on the client from createBrowserClient().",
2216
+ 500,
2217
+ { code: "SDK_DATABASE_FROM_UNAVAILABLE" }
2218
+ );
2219
+ }
2220
+ return this.postgrestFrom(table, databaseInstanceId);
2221
+ }
2172
2222
  toUrl(path) {
2173
2223
  return `${normalizeBrowserApiBase(this.options.baseUrl)}${path.startsWith("/") ? path : `/${path}`}`;
2174
2224
  }
@@ -2282,7 +2332,11 @@ var RagableBrowser = class {
2282
2332
  }
2283
2333
  this.agents = new RagableBrowserAgentsClient(options);
2284
2334
  this.auth = new RagableBrowserAuthClient(options, this._ragableAuth);
2285
- this.database = new RagableBrowserDatabaseClient(options, this._ragableAuth);
2335
+ this.database = new RagableBrowserDatabaseClient(
2336
+ options,
2337
+ this._ragableAuth,
2338
+ (table, databaseInstanceId) => this.from(table, databaseInstanceId)
2339
+ );
2286
2340
  }
2287
2341
  from(table, databaseInstanceId) {
2288
2342
  const id = databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
@@ -2464,6 +2518,7 @@ function createRagableServerClient(options) {
2464
2518
  detectStorage,
2465
2519
  extractErrorMessage,
2466
2520
  formatRetrievalContext,
2521
+ formatSdkError,
2467
2522
  generateIdempotencyKey,
2468
2523
  normalizeBrowserApiBase,
2469
2524
  parseSseDataLine,