@ragable/sdk 0.6.3 → 0.6.4

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
@@ -105,6 +105,11 @@ declare class RagableError extends RagableSdkError {
105
105
  }
106
106
  /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
107
107
  declare function formatSdkError(err: unknown): string;
108
+ /**
109
+ * Human-readable line for a PostgREST `{ data, error }` error (or any thrown value).
110
+ * Use in UI instead of `JSON.stringify(error)` or template strings on unknown errors.
111
+ */
112
+ declare function formatPostgrestError(error: unknown): string;
108
113
  declare class RagableNetworkError extends RagableSdkError {
109
114
  readonly __type: "RagableNetworkError";
110
115
  readonly cause: unknown;
@@ -983,4 +988,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
983
988
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
984
989
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
985
990
 
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 };
991
+ 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, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.d.ts CHANGED
@@ -105,6 +105,11 @@ declare class RagableError extends RagableSdkError {
105
105
  }
106
106
  /** Safe one-line log for any thrown value (catch blocks, TanStack Query). */
107
107
  declare function formatSdkError(err: unknown): string;
108
+ /**
109
+ * Human-readable line for a PostgREST `{ data, error }` error (or any thrown value).
110
+ * Use in UI instead of `JSON.stringify(error)` or template strings on unknown errors.
111
+ */
112
+ declare function formatPostgrestError(error: unknown): string;
108
113
  declare class RagableNetworkError extends RagableSdkError {
109
114
  readonly __type: "RagableNetworkError";
110
115
  readonly cause: unknown;
@@ -983,4 +988,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
983
988
  declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
984
989
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
985
990
 
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 };
991
+ 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, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.js CHANGED
@@ -62,6 +62,7 @@ __export(index_exports, {
62
62
  createRagableServerClient: () => createRagableServerClient,
63
63
  detectStorage: () => detectStorage,
64
64
  extractErrorMessage: () => extractErrorMessage,
65
+ formatPostgrestError: () => formatPostgrestError,
65
66
  formatRetrievalContext: () => formatRetrievalContext,
66
67
  formatSdkError: () => formatSdkError,
67
68
  generateIdempotencyKey: () => generateIdempotencyKey,
@@ -84,6 +85,12 @@ var RagableSdkError = class extends Error {
84
85
  constructor(message) {
85
86
  super(message);
86
87
  this.name = this.constructor.name;
88
+ Object.defineProperty(this, "message", {
89
+ configurable: true,
90
+ enumerable: true,
91
+ writable: true,
92
+ value: message
93
+ });
87
94
  }
88
95
  toJSON() {
89
96
  return {
@@ -103,7 +110,7 @@ var RagableError = class extends RagableSdkError {
103
110
  __publicField(this, "details");
104
111
  this.status = status;
105
112
  this.body = body;
106
- this.code = body && typeof body === "object" ? typeof body.code === "string" ? body.code : void 0 : void 0;
113
+ this.code = body && typeof body === "object" ? typeof body.code === "string" ? body.code : typeof body.code === "number" ? String(body.code) : void 0 : void 0;
107
114
  this.details = body && typeof body === "object" ? typeof body.details === "string" ? body.details : void 0 : void 0;
108
115
  }
109
116
  toJSON() {
@@ -138,11 +145,15 @@ function formatSdkError(err) {
138
145
  try {
139
146
  const s = JSON.stringify(err);
140
147
  if (s !== "{}") return s;
148
+ return "Unknown error (empty object \u2014 avoid `{...error}` spread; use error.message or formatSdkError)";
141
149
  } catch {
142
150
  }
143
151
  }
144
152
  return String(err);
145
153
  }
154
+ function formatPostgrestError(error) {
155
+ return formatSdkError(error);
156
+ }
146
157
  var RagableNetworkError = class extends RagableSdkError {
147
158
  constructor(message, cause) {
148
159
  super(message);
@@ -712,6 +723,27 @@ function encodeFilterValue(op, value) {
712
723
  }
713
724
  return `${op}.${value}`;
714
725
  }
726
+ function extractPostgRESTErrorMessage(payload, status, statusText) {
727
+ const st = (statusText ?? "").trim();
728
+ if (typeof payload !== "object" || payload === null) {
729
+ return st || `HTTP ${status}`;
730
+ }
731
+ const p = payload;
732
+ const raw = p.message ?? p.error ?? p.hint;
733
+ let msg;
734
+ if (typeof raw === "string") {
735
+ msg = raw;
736
+ } else if (typeof raw === "number" || typeof raw === "boolean") {
737
+ msg = String(raw);
738
+ } else if (raw !== null && raw !== void 0 && typeof raw === "object") {
739
+ msg = JSON.stringify(raw);
740
+ } else {
741
+ msg = st || `HTTP ${status}`;
742
+ }
743
+ msg = msg.trim();
744
+ if (!msg) return st || `HTTP ${status}`;
745
+ return msg;
746
+ }
715
747
  async function parsePostgRESTResponse(response) {
716
748
  if (response.status === 204) return null;
717
749
  const text = await response.text();
@@ -727,9 +759,8 @@ async function parsePostgRESTResponse(response) {
727
759
  );
728
760
  }
729
761
  if (!response.ok) {
730
- const msg = typeof payload === "object" && payload !== null ? payload.message ?? payload.error ?? response.statusText : response.statusText;
731
- const code = typeof payload === "object" && payload !== null ? payload.code : void 0;
732
- throw new RagableError(String(msg), response.status, { code });
762
+ const msg = extractPostgRESTErrorMessage(payload, response.status, response.statusText);
763
+ throw new RagableError(msg, response.status, payload);
733
764
  }
734
765
  return payload;
735
766
  }
@@ -2517,6 +2548,7 @@ function createRagableServerClient(options) {
2517
2548
  createRagableServerClient,
2518
2549
  detectStorage,
2519
2550
  extractErrorMessage,
2551
+ formatPostgrestError,
2520
2552
  formatRetrievalContext,
2521
2553
  formatSdkError,
2522
2554
  generateIdempotencyKey,