@ragable/sdk 0.6.21 → 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 +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +126 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -856,6 +856,7 @@ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
|
856
856
|
declare function effectiveDataAuth(options: RagableBrowserClientOptions): BrowserDataAuthMode;
|
|
857
857
|
interface RagableBrowserClientOptions {
|
|
858
858
|
organizationId: string;
|
|
859
|
+
websiteId?: string;
|
|
859
860
|
authGroupId?: string;
|
|
860
861
|
databaseInstanceId?: string;
|
|
861
862
|
/** When omitted, inferred from static keys — see {@link effectiveDataAuth}. */
|
|
@@ -1247,12 +1248,54 @@ interface BrowserRealtimeSubscription {
|
|
|
1247
1248
|
unsubscribe: () => void;
|
|
1248
1249
|
readonly status: BrowserRealtimeStatus;
|
|
1249
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
|
+
}
|
|
1250
1269
|
declare class RagableBrowserAgentsClient {
|
|
1251
1270
|
private readonly options;
|
|
1252
1271
|
private readonly fetchImpl;
|
|
1253
1272
|
constructor(options: RagableBrowserClientOptions);
|
|
1254
1273
|
private toUrl;
|
|
1274
|
+
private requireWebsiteId;
|
|
1275
|
+
private websiteAgentPath;
|
|
1276
|
+
private requestJson;
|
|
1277
|
+
/** @deprecated Prefer `chatStreamByName(agentName, params)` for project-local `/agents/*.json` agents. */
|
|
1255
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;
|
|
1256
1299
|
}
|
|
1257
1300
|
interface AgentPublicChatParams extends AgentChatParams {
|
|
1258
1301
|
triggerSubtype?: string;
|
|
@@ -1348,4 +1391,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
|
|
|
1348
1391
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1349
1392
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
1350
1393
|
|
|
1351
|
-
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 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 };
|
|
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
|
@@ -856,6 +856,7 @@ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
|
856
856
|
declare function effectiveDataAuth(options: RagableBrowserClientOptions): BrowserDataAuthMode;
|
|
857
857
|
interface RagableBrowserClientOptions {
|
|
858
858
|
organizationId: string;
|
|
859
|
+
websiteId?: string;
|
|
859
860
|
authGroupId?: string;
|
|
860
861
|
databaseInstanceId?: string;
|
|
861
862
|
/** When omitted, inferred from static keys — see {@link effectiveDataAuth}. */
|
|
@@ -1247,12 +1248,54 @@ interface BrowserRealtimeSubscription {
|
|
|
1247
1248
|
unsubscribe: () => void;
|
|
1248
1249
|
readonly status: BrowserRealtimeStatus;
|
|
1249
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
|
+
}
|
|
1250
1269
|
declare class RagableBrowserAgentsClient {
|
|
1251
1270
|
private readonly options;
|
|
1252
1271
|
private readonly fetchImpl;
|
|
1253
1272
|
constructor(options: RagableBrowserClientOptions);
|
|
1254
1273
|
private toUrl;
|
|
1274
|
+
private requireWebsiteId;
|
|
1275
|
+
private websiteAgentPath;
|
|
1276
|
+
private requestJson;
|
|
1277
|
+
/** @deprecated Prefer `chatStreamByName(agentName, params)` for project-local `/agents/*.json` agents. */
|
|
1255
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;
|
|
1256
1299
|
}
|
|
1257
1300
|
interface AgentPublicChatParams extends AgentChatParams {
|
|
1258
1301
|
triggerSubtype?: string;
|
|
@@ -1348,4 +1391,4 @@ declare function createClient(options: RagableClientOptions): Ragable;
|
|
|
1348
1391
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1349
1392
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
1350
1393
|
|
|
1351
|
-
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 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 };
|
|
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.js
CHANGED
|
@@ -2808,6 +2808,31 @@ var RagableBrowserAgentsClient = class {
|
|
|
2808
2808
|
toUrl(path) {
|
|
2809
2809
|
return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2810
2810
|
}
|
|
2811
|
+
requireWebsiteId() {
|
|
2812
|
+
const websiteId = this.options.websiteId?.trim();
|
|
2813
|
+
if (!websiteId) {
|
|
2814
|
+
throw new RagableError(
|
|
2815
|
+
"websiteId is required for project agent conversation APIs. Use the generated createWebsiteRagableClient() or pass createBrowserClient({ websiteId, ... }).",
|
|
2816
|
+
400,
|
|
2817
|
+
{ code: "SDK_MISSING_WEBSITE_ID" }
|
|
2818
|
+
);
|
|
2819
|
+
}
|
|
2820
|
+
return websiteId;
|
|
2821
|
+
}
|
|
2822
|
+
websiteAgentPath(path) {
|
|
2823
|
+
const websiteId = this.requireWebsiteId();
|
|
2824
|
+
return `/public/organizations/${this.options.organizationId}/websites/${websiteId}${path}`;
|
|
2825
|
+
}
|
|
2826
|
+
async requestJson(path, init = {}) {
|
|
2827
|
+
const response = await this.fetchImpl(this.toUrl(path), init);
|
|
2828
|
+
const payload = await parseMaybeJsonBody(response);
|
|
2829
|
+
if (!response.ok) {
|
|
2830
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
2831
|
+
throw new RagableError(message, response.status, payload);
|
|
2832
|
+
}
|
|
2833
|
+
return payload;
|
|
2834
|
+
}
|
|
2835
|
+
/** @deprecated Prefer `chatStreamByName(agentName, params)` for project-local `/agents/*.json` agents. */
|
|
2811
2836
|
async *chatStream(agentId, params) {
|
|
2812
2837
|
const orgId = this.options.organizationId;
|
|
2813
2838
|
const body = {
|
|
@@ -2837,6 +2862,107 @@ var RagableBrowserAgentsClient = class {
|
|
|
2837
2862
|
}
|
|
2838
2863
|
yield* readSseStream(streamBody);
|
|
2839
2864
|
}
|
|
2865
|
+
async *chatStreamByName(agentName, params) {
|
|
2866
|
+
const headers = new Headers(this.options.headers);
|
|
2867
|
+
headers.set("Content-Type", "application/json");
|
|
2868
|
+
const response = await this.fetchImpl(
|
|
2869
|
+
this.toUrl(
|
|
2870
|
+
this.websiteAgentPath(
|
|
2871
|
+
`/agents/${encodeURIComponent(agentName)}/chat/stream`
|
|
2872
|
+
)
|
|
2873
|
+
),
|
|
2874
|
+
{
|
|
2875
|
+
method: "POST",
|
|
2876
|
+
headers,
|
|
2877
|
+
body: JSON.stringify({
|
|
2878
|
+
message: params.message,
|
|
2879
|
+
...params.history !== void 0 ? { history: params.history } : {}
|
|
2880
|
+
})
|
|
2881
|
+
}
|
|
2882
|
+
);
|
|
2883
|
+
if (!response.ok) {
|
|
2884
|
+
const payload = await parseMaybeJsonBody(response);
|
|
2885
|
+
const message = extractErrorMessage(payload, response.statusText);
|
|
2886
|
+
throw new RagableError(message, response.status, payload);
|
|
2887
|
+
}
|
|
2888
|
+
if (!response.body) return;
|
|
2889
|
+
yield* readSseStream(response.body);
|
|
2890
|
+
}
|
|
2891
|
+
createConversation(params) {
|
|
2892
|
+
const headers = new Headers(this.options.headers);
|
|
2893
|
+
headers.set("Content-Type", "application/json");
|
|
2894
|
+
return this.requestJson(
|
|
2895
|
+
this.websiteAgentPath("/agent-conversations"),
|
|
2896
|
+
{
|
|
2897
|
+
method: "POST",
|
|
2898
|
+
headers,
|
|
2899
|
+
body: JSON.stringify(params)
|
|
2900
|
+
}
|
|
2901
|
+
);
|
|
2902
|
+
}
|
|
2903
|
+
listConversations(params = {}) {
|
|
2904
|
+
const agentName = params.agent_name ?? params.agentName;
|
|
2905
|
+
const qs = agentName ? `?agentName=${encodeURIComponent(agentName)}` : "";
|
|
2906
|
+
return this.requestJson(
|
|
2907
|
+
this.websiteAgentPath(`/agent-conversations${qs}`)
|
|
2908
|
+
);
|
|
2909
|
+
}
|
|
2910
|
+
getConversation(conversationId) {
|
|
2911
|
+
return this.requestJson(
|
|
2912
|
+
this.websiteAgentPath(
|
|
2913
|
+
`/agent-conversations/${encodeURIComponent(conversationId)}`
|
|
2914
|
+
)
|
|
2915
|
+
);
|
|
2916
|
+
}
|
|
2917
|
+
updateConversation(conversationId, data) {
|
|
2918
|
+
const headers = new Headers(this.options.headers);
|
|
2919
|
+
headers.set("Content-Type", "application/json");
|
|
2920
|
+
return this.requestJson(
|
|
2921
|
+
this.websiteAgentPath(
|
|
2922
|
+
`/agent-conversations/${encodeURIComponent(conversationId)}`
|
|
2923
|
+
),
|
|
2924
|
+
{
|
|
2925
|
+
method: "PATCH",
|
|
2926
|
+
headers,
|
|
2927
|
+
body: JSON.stringify(data)
|
|
2928
|
+
}
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
addMessage(conversationOrId, message) {
|
|
2932
|
+
const conversationId = typeof conversationOrId === "string" ? conversationOrId : conversationOrId.id;
|
|
2933
|
+
const headers = new Headers(this.options.headers);
|
|
2934
|
+
headers.set("Content-Type", "application/json");
|
|
2935
|
+
return this.requestJson(
|
|
2936
|
+
this.websiteAgentPath(
|
|
2937
|
+
`/agent-conversations/${encodeURIComponent(conversationId)}/messages`
|
|
2938
|
+
),
|
|
2939
|
+
{
|
|
2940
|
+
method: "POST",
|
|
2941
|
+
headers,
|
|
2942
|
+
body: JSON.stringify(message)
|
|
2943
|
+
}
|
|
2944
|
+
);
|
|
2945
|
+
}
|
|
2946
|
+
subscribeToConversation(conversationId, callback, options = {}) {
|
|
2947
|
+
let stopped = false;
|
|
2948
|
+
let timer = null;
|
|
2949
|
+
const intervalMs = Math.max(500, options.intervalMs ?? 1500);
|
|
2950
|
+
const tick = async () => {
|
|
2951
|
+
if (stopped) return;
|
|
2952
|
+
try {
|
|
2953
|
+
callback(await this.getConversation(conversationId));
|
|
2954
|
+
} finally {
|
|
2955
|
+
if (!stopped) timer = setTimeout(tick, intervalMs);
|
|
2956
|
+
}
|
|
2957
|
+
};
|
|
2958
|
+
void tick();
|
|
2959
|
+
return {
|
|
2960
|
+
unsubscribe: () => {
|
|
2961
|
+
stopped = true;
|
|
2962
|
+
if (timer) clearTimeout(timer);
|
|
2963
|
+
}
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2840
2966
|
};
|
|
2841
2967
|
var RagableBrowser = class {
|
|
2842
2968
|
constructor(options) {
|