@ragable/sdk 0.7.5 → 0.7.7

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.js CHANGED
@@ -22,8 +22,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22
22
  // src/index.ts
23
23
  var index_exports = {};
24
24
  __export(index_exports, {
25
- AgentsClient: () => AgentsClient,
26
25
  AuthBroadcastChannel: () => AuthBroadcastChannel,
26
+ BrowserStorageBucketClient: () => BrowserStorageBucketClient,
27
27
  CookieStorageAdapter: () => CookieStorageAdapter,
28
28
  DEFAULT_RAGABLE_API_BASE: () => DEFAULT_RAGABLE_API_BASE,
29
29
  LocalStorageAdapter: () => LocalStorageAdapter,
@@ -40,43 +40,42 @@ __export(index_exports, {
40
40
  PostgrestUpdateRootBuilder: () => PostgrestUpdateRootBuilder,
41
41
  PostgrestUpsertReturningBuilder: () => PostgrestUpsertReturningBuilder,
42
42
  PostgrestUpsertRootBuilder: () => PostgrestUpsertRootBuilder,
43
- Ragable: () => Ragable,
44
43
  RagableAbortError: () => RagableAbortError,
45
44
  RagableAuth: () => RagableAuth,
46
45
  RagableBrowser: () => RagableBrowser,
47
46
  RagableBrowserAgentsClient: () => RagableBrowserAgentsClient,
47
+ RagableBrowserAiClient: () => RagableBrowserAiClient,
48
48
  RagableBrowserAuthClient: () => RagableBrowserAuthClient,
49
49
  RagableBrowserDatabaseClient: () => RagableBrowserDatabaseClient,
50
+ RagableBrowserStorageClient: () => RagableBrowserStorageClient,
50
51
  RagableError: () => RagableError,
51
52
  RagableNetworkError: () => RagableNetworkError,
52
- RagableRequestClient: () => RagableRequestClient,
53
53
  RagableSdkError: () => RagableSdkError,
54
54
  RagableTimeoutError: () => RagableTimeoutError,
55
55
  SessionStorageAdapter: () => SessionStorageAdapter,
56
- ShiftClient: () => ShiftClient,
57
- StorageClient: () => StorageClient,
58
56
  Transport: () => Transport,
59
57
  asPostgrestResponse: () => asPostgrestResponse,
60
58
  assertPostgrestSuccess: () => assertPostgrestSuccess,
61
59
  bindFetch: () => bindFetch,
60
+ buildInferenceRequestBody: () => buildInferenceRequestBody,
62
61
  collectAssistantTextFromUiSegments: () => collectAssistantTextFromUiSegments,
63
62
  collectionRecordToRowWithMeta: () => collectionRecordToRowWithMeta,
64
63
  collectionRecordsToRowWithMeta: () => collectionRecordsToRowWithMeta,
65
64
  createBrowserClient: () => createBrowserClient,
66
65
  createClient: () => createClient,
67
- createRagPipeline: () => createRagPipeline,
68
66
  createRagableBrowserClient: () => createRagableBrowserClient,
69
- createRagableServerClient: () => createRagableServerClient,
67
+ createStreamResultFromParts: () => createStreamResultFromParts,
70
68
  detectStorage: () => detectStorage,
71
69
  effectiveDataAuth: () => effectiveDataAuth,
72
70
  extractErrorMessage: () => extractErrorMessage,
73
71
  finalizeAgentChatUiTurn: () => finalizeAgentChatUiTurn,
74
72
  foldAgentStreamIntoUiSegments: () => foldAgentStreamIntoUiSegments,
75
73
  formatPostgrestError: () => formatPostgrestError,
76
- formatRetrievalContext: () => formatRetrievalContext,
77
74
  formatSdkError: () => formatSdkError,
78
75
  generateIdempotencyKey: () => generateIdempotencyKey,
79
76
  isIncompleteAgentStreamError: () => isIncompleteAgentStreamError,
77
+ mapAgentEvent: () => mapAgentEvent,
78
+ mapFireworksChunk: () => mapFireworksChunk,
80
79
  normalizeBrowserApiBase: () => normalizeBrowserApiBase,
81
80
  parseAgentStreamAgentInfo: () => parseAgentStreamAgentInfo,
82
81
  parseAgentStreamDone: () => parseAgentStreamDone,
@@ -220,201 +219,6 @@ function extractErrorMessage(payload, fallback) {
220
219
  }
221
220
  return fallback || "Request failed";
222
221
  }
223
- var RagableRequestClient = class {
224
- constructor(options) {
225
- __publicField(this, "apiKey");
226
- __publicField(this, "baseUrl");
227
- __publicField(this, "fetchImpl");
228
- __publicField(this, "defaultHeaders");
229
- this.apiKey = options.apiKey;
230
- this.baseUrl = DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
231
- this.fetchImpl = bindFetch(options.fetch);
232
- this.defaultHeaders = options.headers;
233
- }
234
- toUrl(path) {
235
- const normalizedBase = this.baseUrl.replace(/\/+$/, "");
236
- const normalizedPath = path.startsWith("/") ? path : `/${path}`;
237
- return `${normalizedBase}${normalizedPath}`;
238
- }
239
- async request(path, options = {}) {
240
- const response = await this.rawFetch(path, options);
241
- const payload = await this.parseResponseBody(response);
242
- if (!response.ok) {
243
- const message = extractErrorMessage(payload, response.statusText);
244
- throw new RagableError(message, response.status, payload);
245
- }
246
- return payload;
247
- }
248
- /**
249
- * Low-level fetch with API key and JSON body encoding. Caller handles status and body.
250
- */
251
- async rawFetch(path, options = {}) {
252
- const headers = new Headers(this.defaultHeaders);
253
- headers.set("Authorization", `Bearer ${this.apiKey}`);
254
- let body = options.body;
255
- if (body !== void 0 && !isBodyInit(body)) {
256
- headers.set("Content-Type", "application/json");
257
- body = JSON.stringify(body);
258
- }
259
- return this.fetchImpl(this.toUrl(path), {
260
- ...options,
261
- headers,
262
- body
263
- });
264
- }
265
- async parseResponseBody(response) {
266
- if (response.status === 204) {
267
- return null;
268
- }
269
- const contentType = response.headers.get("content-type") ?? "";
270
- if (contentType.includes("application/json")) {
271
- return response.json();
272
- }
273
- return response.text();
274
- }
275
- };
276
- function isBodyInit(value) {
277
- return typeof value === "string" || value instanceof Blob || value instanceof FormData || value instanceof URLSearchParams || value instanceof ArrayBuffer || ArrayBuffer.isView(value);
278
- }
279
-
280
- // src/shift.ts
281
- var ShiftClient = class {
282
- constructor(client) {
283
- this.client = client;
284
- __publicField(this, "indexes");
285
- __publicField(this, "documents");
286
- __publicField(this, "entries");
287
- this.indexes = {
288
- list: async () => {
289
- return this.client.request("/v1/shift/indexes");
290
- },
291
- create: async (params) => {
292
- return this.client.request("/v1/shift/indexes", {
293
- method: "POST",
294
- body: params
295
- });
296
- },
297
- get: async (indexId) => {
298
- return this.client.request(`/v1/shift/indexes/${indexId}`);
299
- },
300
- update: async (indexId, params) => {
301
- return this.client.request(`/v1/shift/indexes/${indexId}`, {
302
- method: "PUT",
303
- body: params
304
- });
305
- },
306
- delete: async (indexId) => {
307
- return this.client.request(
308
- `/v1/shift/indexes/${indexId}`,
309
- {
310
- method: "DELETE"
311
- }
312
- );
313
- }
314
- };
315
- this.documents = {
316
- create: async (indexId, params) => {
317
- return this.client.request(
318
- `/v1/shift/indexes/${indexId}/documents`,
319
- {
320
- method: "POST",
321
- body: params
322
- }
323
- );
324
- },
325
- upload: async (indexId, params) => {
326
- const formData = new FormData();
327
- const fileName = resolveUploadFileName(params);
328
- const contentType = resolveUploadContentType(params);
329
- const file = normalizeUploadFile(params.file, contentType);
330
- formData.set("file", file, fileName);
331
- if (params.metadata) {
332
- formData.set("metadata", JSON.stringify(params.metadata));
333
- }
334
- if (typeof params.chunkSize === "number") {
335
- formData.set("chunkSize", String(params.chunkSize));
336
- }
337
- if (typeof params.chunkOverlap === "number") {
338
- formData.set("chunkOverlap", String(params.chunkOverlap));
339
- }
340
- return this.client.request(
341
- `/v1/shift/indexes/${indexId}/files`,
342
- {
343
- method: "POST",
344
- body: formData
345
- }
346
- );
347
- }
348
- };
349
- this.entries = {
350
- list: async (indexId, params = {}) => {
351
- const search = new URLSearchParams();
352
- if (typeof params.take === "number") {
353
- search.set("take", String(params.take));
354
- }
355
- if (typeof params.skip === "number") {
356
- search.set("skip", String(params.skip));
357
- }
358
- const suffix = search.size > 0 ? `?${search.toString()}` : "";
359
- return this.client.request(
360
- `/v1/shift/indexes/${indexId}/entries${suffix}`
361
- );
362
- },
363
- delete: async (indexId, entryId) => {
364
- return this.client.request(
365
- `/v1/shift/indexes/${indexId}/entries/${entryId}`,
366
- {
367
- method: "DELETE"
368
- }
369
- );
370
- }
371
- };
372
- }
373
- async search(indexId, params) {
374
- return this.client.request(
375
- `/v1/shift/indexes/${indexId}/search`,
376
- {
377
- method: "POST",
378
- body: params
379
- }
380
- );
381
- }
382
- };
383
- function resolveUploadFileName(params) {
384
- if (params.fileName) {
385
- return params.fileName;
386
- }
387
- if (isNamedBlob(params.file)) {
388
- return params.file.name;
389
- }
390
- return "upload.bin";
391
- }
392
- function resolveUploadContentType(params) {
393
- if (params.contentType) {
394
- return params.contentType;
395
- }
396
- if (params.file instanceof Blob && params.file.type) {
397
- return params.file.type;
398
- }
399
- return "application/octet-stream";
400
- }
401
- function normalizeUploadFile(file, contentType) {
402
- if (file instanceof Blob) {
403
- return file;
404
- }
405
- if (file instanceof Uint8Array) {
406
- return new Blob([toArrayBuffer(file)], { type: contentType });
407
- }
408
- return new Blob([file], { type: contentType });
409
- }
410
- function isNamedBlob(value) {
411
- return value instanceof Blob && "name" in value && typeof value.name === "string";
412
- }
413
- function toArrayBuffer(value) {
414
- const copy = new Uint8Array(value.byteLength);
415
- copy.set(value);
416
- return copy.buffer;
417
- }
418
222
 
419
223
  // src/agent-stream.ts
420
224
  function assertAborted(signal) {
@@ -920,72 +724,6 @@ async function* readSseStream(body) {
920
724
  }
921
725
  }
922
726
 
923
- // src/agents.ts
924
- var AgentsClient = class {
925
- constructor(client) {
926
- this.client = client;
927
- }
928
- async list() {
929
- return this.client.request("/v1/agents");
930
- }
931
- async get(agentId) {
932
- return this.client.request(`/v1/agents/${agentId}`);
933
- }
934
- async chat(agentId, params) {
935
- return this.client.request(`/v1/agents/${agentId}/chat`, {
936
- method: "POST",
937
- body: {
938
- message: params.message,
939
- ...params.history !== void 0 ? { history: params.history } : {}
940
- }
941
- });
942
- }
943
- /**
944
- * Stream agent execution as SSE (`data: {json}` lines). Yields parsed JSON objects.
945
- */
946
- async *chatStream(agentId, params) {
947
- const response = await this.client.rawFetch(
948
- `/v1/agents/${agentId}/chat/stream`,
949
- {
950
- method: "POST",
951
- body: {
952
- message: params.message,
953
- ...params.history !== void 0 ? { history: params.history } : {}
954
- },
955
- ...params.signal !== void 0 ? { signal: params.signal } : {}
956
- }
957
- );
958
- if (!response.ok) {
959
- const payload = await parseMaybeJsonBody(response);
960
- const message = extractErrorMessage(payload, response.statusText);
961
- throw new RagableError(message, response.status, payload);
962
- }
963
- const body = response.body;
964
- if (!body) {
965
- return;
966
- }
967
- yield* readSseStream(body);
968
- }
969
- /**
970
- * Stream an agent turn with callbacks; returns the final `done` payload plus streamed text.
971
- * Prefer this over manual iteration when building chat UIs against the server API key client.
972
- */
973
- async runChatStream(agentId, params, handlers = {}) {
974
- return runAgentChatStream(this.chatStream(agentId, params), handlers, {
975
- signal: params.signal
976
- });
977
- }
978
- /**
979
- * Stream with dashboard-style `AgentChat` ergonomics: {@link AgentChatStreamUiHandlers.onSegments}
980
- * / `onStreamingText` for live UI; returns a persisted-shaped assistant message on `done`.
981
- */
982
- async runChatUi(agentId, params, handlers = {}) {
983
- return runAgentChatStreamForUi(this.chatStream(agentId, params), handlers, {
984
- signal: params.signal
985
- });
986
- }
987
- };
988
-
989
727
  // src/transport.ts
990
728
  var DEFAULT_RETRY = {
991
729
  maxRetries: 3,
@@ -2214,8 +1952,8 @@ function parseExpiresInSeconds(raw) {
2214
1952
  const mult = u === "s" ? 1 : u === "m" ? 60 : u === "h" ? 3600 : u === "d" ? 86400 : 1;
2215
1953
  return n * mult;
2216
1954
  }
2217
- const asNum = Number(s);
2218
- return Number.isFinite(asNum) ? asNum : 0;
1955
+ const asNum2 = Number(s);
1956
+ return Number.isFinite(asNum2) ? asNum2 : 0;
2219
1957
  }
2220
1958
  async function parseJsonOrThrow(response) {
2221
1959
  const text = await response.text();
@@ -2619,6 +2357,480 @@ function decodeJwtExpiry(jwt) {
2619
2357
  }
2620
2358
  }
2621
2359
 
2360
+ // src/stream-parts.ts
2361
+ function normalizeFinishReason(raw) {
2362
+ switch (raw) {
2363
+ case "stop":
2364
+ case "length":
2365
+ case "content-filter":
2366
+ case "error":
2367
+ return raw;
2368
+ case "tool_calls":
2369
+ return "tool-calls";
2370
+ case null:
2371
+ case void 0:
2372
+ case "":
2373
+ return "unknown";
2374
+ default:
2375
+ return "unknown";
2376
+ }
2377
+ }
2378
+ function chunkUsage(chunk) {
2379
+ const u = chunk.usage ?? {};
2380
+ const cached = u.prompt_tokens_details?.cached_tokens ?? u.cache_read_input_tokens;
2381
+ return {
2382
+ promptTokens: typeof u.prompt_tokens === "number" ? u.prompt_tokens : 0,
2383
+ completionTokens: typeof u.completion_tokens === "number" ? u.completion_tokens : 0,
2384
+ totalTokens: typeof u.total_tokens === "number" ? u.total_tokens : 0,
2385
+ ...typeof cached === "number" ? { cachedPromptTokens: cached } : {}
2386
+ };
2387
+ }
2388
+ function createToolCallAccumulator() {
2389
+ return { byIndex: /* @__PURE__ */ new Map() };
2390
+ }
2391
+ function parseJsonOrRaw(raw) {
2392
+ try {
2393
+ return JSON.parse(raw);
2394
+ } catch {
2395
+ return raw;
2396
+ }
2397
+ }
2398
+ function mapFireworksChunk(chunk, acc) {
2399
+ const out = [];
2400
+ if (chunk.error?.message) {
2401
+ out.push({ type: "error", error: chunk.error.message });
2402
+ return out;
2403
+ }
2404
+ const choice = chunk.choices?.[0];
2405
+ const delta = choice?.delta;
2406
+ if (delta?.content) {
2407
+ out.push({ type: "text-delta", textDelta: delta.content });
2408
+ }
2409
+ const reasoning = delta?.reasoning_content ?? delta?.reasoning;
2410
+ if (typeof reasoning === "string" && reasoning.length > 0) {
2411
+ out.push({ type: "reasoning", textDelta: reasoning });
2412
+ }
2413
+ if (Array.isArray(delta?.tool_calls)) {
2414
+ for (const tc of delta.tool_calls) {
2415
+ const idx = typeof tc.index === "number" ? tc.index : 0;
2416
+ let entry = acc.byIndex.get(idx);
2417
+ if (!entry) {
2418
+ entry = { id: "", name: "", argsBuffer: "", emitted: false };
2419
+ acc.byIndex.set(idx, entry);
2420
+ }
2421
+ if (tc.id) entry.id = tc.id;
2422
+ if (tc.function?.name) entry.name = tc.function.name;
2423
+ if (typeof tc.function?.arguments === "string") {
2424
+ entry.argsBuffer += tc.function.arguments;
2425
+ }
2426
+ }
2427
+ }
2428
+ if (choice?.finish_reason) {
2429
+ for (const entry of acc.byIndex.values()) {
2430
+ if (entry.emitted || !entry.name) continue;
2431
+ entry.emitted = true;
2432
+ out.push({
2433
+ type: "tool-call",
2434
+ toolCallId: entry.id || `call_${entry.name}_${Date.now()}`,
2435
+ toolName: entry.name,
2436
+ args: entry.argsBuffer ? parseJsonOrRaw(entry.argsBuffer) : {}
2437
+ });
2438
+ }
2439
+ out.push({
2440
+ type: "finish",
2441
+ finishReason: normalizeFinishReason(choice.finish_reason),
2442
+ usage: chunkUsage(chunk)
2443
+ });
2444
+ } else if (chunk.usage) {
2445
+ out.push({
2446
+ type: "finish",
2447
+ finishReason: "unknown",
2448
+ usage: chunkUsage(chunk)
2449
+ });
2450
+ }
2451
+ return out;
2452
+ }
2453
+ function asStr(v, fallback = "") {
2454
+ return typeof v === "string" ? v : fallback;
2455
+ }
2456
+ function asNum(v, fallback = 0) {
2457
+ return typeof v === "number" && Number.isFinite(v) ? v : fallback;
2458
+ }
2459
+ function mapAgentEvent(event) {
2460
+ switch (event.type) {
2461
+ case "token":
2462
+ return { type: "text-delta", textDelta: asStr(event.token) };
2463
+ case "reasoning_token":
2464
+ return { type: "reasoning", textDelta: asStr(event.token) };
2465
+ case "tool:call":
2466
+ return {
2467
+ type: "tool-call",
2468
+ toolCallId: asStr(event.nodeId),
2469
+ toolName: asStr(event.toolName),
2470
+ args: event.args
2471
+ };
2472
+ case "tool:result":
2473
+ return {
2474
+ type: "tool-result",
2475
+ toolCallId: asStr(event.nodeId),
2476
+ toolName: asStr(event.toolName),
2477
+ result: event.result,
2478
+ ...typeof event.durationMs === "number" ? { durationMs: event.durationMs } : {}
2479
+ };
2480
+ case "done": {
2481
+ const usage = {
2482
+ promptTokens: asNum(event.inputTokens),
2483
+ completionTokens: asNum(event.outputTokens),
2484
+ totalTokens: asNum(event.inputTokens) + asNum(event.outputTokens),
2485
+ ...typeof event.cachedPromptTokens === "number" ? { cachedPromptTokens: event.cachedPromptTokens } : {}
2486
+ };
2487
+ return {
2488
+ type: "finish",
2489
+ finishReason: normalizeFinishReason(
2490
+ asStr(event.finishReason) || asStr(event.stopReason) || null
2491
+ ),
2492
+ usage
2493
+ };
2494
+ }
2495
+ default:
2496
+ return null;
2497
+ }
2498
+ }
2499
+
2500
+ // src/ai.ts
2501
+ var PartBroadcast = class {
2502
+ constructor() {
2503
+ __publicField(this, "state", {
2504
+ parts: [],
2505
+ resolved: false,
2506
+ error: null,
2507
+ waiters: []
2508
+ });
2509
+ }
2510
+ push(part) {
2511
+ this.state.parts.push(part);
2512
+ this.notify();
2513
+ }
2514
+ end() {
2515
+ if (this.state.resolved) return;
2516
+ this.state.resolved = true;
2517
+ this.notify();
2518
+ }
2519
+ fail(error) {
2520
+ if (this.state.resolved) return;
2521
+ this.state.error = error;
2522
+ this.state.resolved = true;
2523
+ this.notify();
2524
+ }
2525
+ notify() {
2526
+ const waiters = this.state.waiters;
2527
+ this.state.waiters = [];
2528
+ for (const w of waiters) w();
2529
+ }
2530
+ consume() {
2531
+ const state = this.state;
2532
+ return {
2533
+ [Symbol.asyncIterator]: () => {
2534
+ let idx = 0;
2535
+ return {
2536
+ next: async () => {
2537
+ while (true) {
2538
+ if (idx < state.parts.length) {
2539
+ return { value: state.parts[idx++], done: false };
2540
+ }
2541
+ if (state.resolved) {
2542
+ if (state.error) throw state.error;
2543
+ return { value: void 0, done: true };
2544
+ }
2545
+ await new Promise((resolve) => {
2546
+ state.waiters.push(resolve);
2547
+ });
2548
+ }
2549
+ }
2550
+ };
2551
+ }
2552
+ };
2553
+ }
2554
+ };
2555
+ function defer() {
2556
+ let resolve;
2557
+ let reject;
2558
+ const promise = new Promise((res, rej) => {
2559
+ resolve = res;
2560
+ reject = rej;
2561
+ });
2562
+ return { promise, resolve, reject };
2563
+ }
2564
+ var ZERO_USAGE = {
2565
+ promptTokens: 0,
2566
+ completionTokens: 0,
2567
+ totalTokens: 0
2568
+ };
2569
+ function buildInferenceRequestBody(params) {
2570
+ const body = {
2571
+ model: params.model,
2572
+ messages: params.messages
2573
+ };
2574
+ if (params.system !== void 0) body.system = params.system;
2575
+ if (typeof params.temperature === "number")
2576
+ body.temperature = params.temperature;
2577
+ if (typeof params.maxTokens === "number") body.max_tokens = params.maxTokens;
2578
+ if (typeof params.topP === "number") body.top_p = params.topP;
2579
+ if (params.reasoningEffort) body.reasoning_effort = params.reasoningEffort;
2580
+ return body;
2581
+ }
2582
+ async function consumeInferenceStream(body, broadcast, deferreds) {
2583
+ const reader = body.getReader();
2584
+ const decoder = new TextDecoder();
2585
+ const acc = createToolCallAccumulator();
2586
+ let textBuffer = "";
2587
+ let reasoningBuffer = "";
2588
+ let lastUsage = ZERO_USAGE;
2589
+ let lastFinish = "unknown";
2590
+ const toolCallsArr = [];
2591
+ let buffer = "";
2592
+ const dispatch = (rawLine) => {
2593
+ const parsed = parseSseDataLine(rawLine);
2594
+ if (!parsed) return;
2595
+ const chunk = parsed;
2596
+ const parts = mapFireworksChunk(chunk, acc);
2597
+ for (const part of parts) {
2598
+ if (part.type === "text-delta") textBuffer += part.textDelta;
2599
+ else if (part.type === "reasoning") reasoningBuffer += part.textDelta;
2600
+ else if (part.type === "tool-call") {
2601
+ toolCallsArr.push({
2602
+ toolCallId: part.toolCallId,
2603
+ toolName: part.toolName,
2604
+ args: part.args
2605
+ });
2606
+ } else if (part.type === "finish") {
2607
+ lastFinish = part.finishReason;
2608
+ lastUsage = part.usage;
2609
+ }
2610
+ broadcast.push(part);
2611
+ }
2612
+ };
2613
+ try {
2614
+ while (true) {
2615
+ const { done, value } = await reader.read();
2616
+ if (done) break;
2617
+ buffer += decoder.decode(value, { stream: true });
2618
+ let boundary = buffer.indexOf("\n\n");
2619
+ while (boundary !== -1) {
2620
+ const block = buffer.slice(0, boundary);
2621
+ buffer = buffer.slice(boundary + 2);
2622
+ for (const line of block.split("\n")) dispatch(line);
2623
+ boundary = buffer.indexOf("\n\n");
2624
+ }
2625
+ }
2626
+ if (buffer.trim().length > 0) {
2627
+ for (const line of buffer.split("\n")) dispatch(line);
2628
+ }
2629
+ broadcast.end();
2630
+ deferreds.text.resolve(textBuffer);
2631
+ deferreds.reasoning.resolve(reasoningBuffer);
2632
+ deferreds.usage.resolve(lastUsage);
2633
+ deferreds.finishReason.resolve(lastFinish);
2634
+ deferreds.toolCalls.resolve(toolCallsArr);
2635
+ } catch (error) {
2636
+ broadcast.fail(error);
2637
+ deferreds.text.reject(error);
2638
+ deferreds.reasoning.reject(error);
2639
+ deferreds.usage.reject(error);
2640
+ deferreds.finishReason.reject(error);
2641
+ deferreds.toolCalls.reject(error);
2642
+ } finally {
2643
+ try {
2644
+ reader.releaseLock();
2645
+ } catch {
2646
+ }
2647
+ }
2648
+ }
2649
+ function createStreamResultFromParts(source) {
2650
+ const broadcast = new PartBroadcast();
2651
+ const text = defer();
2652
+ const reasoning = defer();
2653
+ const usage = defer();
2654
+ const finishReason = defer();
2655
+ const toolCalls = defer();
2656
+ void (async () => {
2657
+ let textBuffer = "";
2658
+ let reasoningBuffer = "";
2659
+ let lastUsage = ZERO_USAGE;
2660
+ let lastFinish = "unknown";
2661
+ const toolCallsArr = [];
2662
+ try {
2663
+ for await (const part of source) {
2664
+ if (part.type === "text-delta") textBuffer += part.textDelta;
2665
+ else if (part.type === "reasoning")
2666
+ reasoningBuffer += part.textDelta;
2667
+ else if (part.type === "tool-call") {
2668
+ toolCallsArr.push({
2669
+ toolCallId: part.toolCallId,
2670
+ toolName: part.toolName,
2671
+ args: part.args
2672
+ });
2673
+ } else if (part.type === "finish") {
2674
+ lastFinish = part.finishReason;
2675
+ lastUsage = part.usage;
2676
+ }
2677
+ broadcast.push(part);
2678
+ }
2679
+ broadcast.end();
2680
+ text.resolve(textBuffer);
2681
+ reasoning.resolve(reasoningBuffer);
2682
+ usage.resolve(lastUsage);
2683
+ finishReason.resolve(lastFinish);
2684
+ toolCalls.resolve(toolCallsArr);
2685
+ } catch (error) {
2686
+ broadcast.fail(error);
2687
+ text.reject(error);
2688
+ reasoning.reject(error);
2689
+ usage.reject(error);
2690
+ finishReason.reject(error);
2691
+ toolCalls.reject(error);
2692
+ }
2693
+ })();
2694
+ return {
2695
+ fullStream: broadcast.consume(),
2696
+ textStream: {
2697
+ [Symbol.asyncIterator]: () => {
2698
+ const inner = broadcast.consume()[Symbol.asyncIterator]();
2699
+ return {
2700
+ next: async () => {
2701
+ while (true) {
2702
+ const r = await inner.next();
2703
+ if (r.done)
2704
+ return { value: void 0, done: true };
2705
+ if (r.value.type === "text-delta") {
2706
+ return { value: r.value.textDelta, done: false };
2707
+ }
2708
+ }
2709
+ }
2710
+ };
2711
+ }
2712
+ },
2713
+ text: text.promise,
2714
+ reasoning: reasoning.promise,
2715
+ usage: usage.promise,
2716
+ finishReason: finishReason.promise,
2717
+ toolCalls: toolCalls.promise
2718
+ };
2719
+ }
2720
+ function streamInferenceFromContext(ctx, params) {
2721
+ const broadcast = new PartBroadcast();
2722
+ const text = defer();
2723
+ const reasoning = defer();
2724
+ const usage = defer();
2725
+ const finishReason = defer();
2726
+ const toolCalls = defer();
2727
+ const start = async () => {
2728
+ const response = await ctx.fetch(ctx.url, {
2729
+ method: "POST",
2730
+ headers: ctx.headers,
2731
+ body: JSON.stringify(buildInferenceRequestBody(params)),
2732
+ ...params.signal !== void 0 ? { signal: params.signal } : {}
2733
+ });
2734
+ if (!response.ok) {
2735
+ const payload = await parseMaybeJsonBody(response);
2736
+ const message = extractErrorMessage(payload, response.statusText);
2737
+ throw new RagableError(message, response.status, payload);
2738
+ }
2739
+ if (!response.body) {
2740
+ throw new RagableError("Inference stream has no body", 502, {
2741
+ code: "SDK_INFERENCE_STREAM_NO_BODY"
2742
+ });
2743
+ }
2744
+ await consumeInferenceStream(response.body, broadcast, {
2745
+ text,
2746
+ reasoning,
2747
+ usage,
2748
+ finishReason,
2749
+ toolCalls
2750
+ });
2751
+ };
2752
+ start().catch((err) => {
2753
+ broadcast.fail(err);
2754
+ text.reject(err);
2755
+ reasoning.reject(err);
2756
+ usage.reject(err);
2757
+ finishReason.reject(err);
2758
+ toolCalls.reject(err);
2759
+ });
2760
+ return {
2761
+ fullStream: broadcast.consume(),
2762
+ textStream: {
2763
+ [Symbol.asyncIterator]: () => {
2764
+ const inner = broadcast.consume()[Symbol.asyncIterator]();
2765
+ return {
2766
+ next: async () => {
2767
+ while (true) {
2768
+ const r = await inner.next();
2769
+ if (r.done) return { value: void 0, done: true };
2770
+ if (r.value.type === "text-delta") {
2771
+ return { value: r.value.textDelta, done: false };
2772
+ }
2773
+ }
2774
+ }
2775
+ };
2776
+ }
2777
+ },
2778
+ text: text.promise,
2779
+ reasoning: reasoning.promise,
2780
+ usage: usage.promise,
2781
+ finishReason: finishReason.promise,
2782
+ toolCalls: toolCalls.promise
2783
+ };
2784
+ }
2785
+ var RagableBrowserAiClient = class {
2786
+ constructor(options) {
2787
+ this.options = options;
2788
+ __publicField(this, "fetchImpl");
2789
+ this.fetchImpl = bindFetch(options.fetch);
2790
+ }
2791
+ requireWebsiteId() {
2792
+ const id = this.options.websiteId?.trim();
2793
+ if (!id) {
2794
+ throw new RagableError(
2795
+ "client.ai.streamText requires websiteId on the client. Pass createBrowserClient({ websiteId, organizationId, ... }).",
2796
+ 400,
2797
+ { code: "SDK_MISSING_WEBSITE_ID" }
2798
+ );
2799
+ }
2800
+ return id;
2801
+ }
2802
+ buildContext() {
2803
+ const url = `${this.options.apiBase}/public/organizations/${encodeURIComponent(
2804
+ this.options.organizationId
2805
+ )}/websites/${encodeURIComponent(
2806
+ this.requireWebsiteId()
2807
+ )}/inference/stream`;
2808
+ const headers = new Headers(this.options.headers);
2809
+ headers.set("Content-Type", "application/json");
2810
+ headers.set("Accept", "text/event-stream");
2811
+ return { url, headers, fetch: this.fetchImpl };
2812
+ }
2813
+ streamText(params) {
2814
+ return streamInferenceFromContext(this.buildContext(), params);
2815
+ }
2816
+ async generateText(params) {
2817
+ const result = this.streamText(params);
2818
+ for await (const _ of result.fullStream) {
2819
+ void _;
2820
+ }
2821
+ const [text, reasoning, usage, finishReason, toolCalls] = await Promise.all(
2822
+ [
2823
+ result.text,
2824
+ result.reasoning,
2825
+ result.usage,
2826
+ result.finishReason,
2827
+ result.toolCalls
2828
+ ]
2829
+ );
2830
+ return { text, reasoning, usage, finishReason, toolCalls };
2831
+ }
2832
+ };
2833
+
2622
2834
  // src/browser.ts
2623
2835
  function normalizeBrowserApiBase() {
2624
2836
  return DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
@@ -3291,6 +3503,113 @@ async function subscribeBrowserRealtime(options, ragableAuth, fetchImpl, params)
3291
3503
  })();
3292
3504
  return subscription;
3293
3505
  }
3506
+ var BrowserStorageBucketClient = class {
3507
+ constructor(options, fetchImpl, bucketId) {
3508
+ this.options = options;
3509
+ this.fetchImpl = fetchImpl;
3510
+ this.bucketId = bucketId;
3511
+ }
3512
+ get authGroupId() {
3513
+ const id = this.options.authGroupId?.trim();
3514
+ if (!id) throw new RagableError("authGroupId is required for storage", 400, { code: "SDK_MISSING_AUTH_GROUP_ID" });
3515
+ return id;
3516
+ }
3517
+ base() {
3518
+ return `${normalizeBrowserApiBase()}/auth-groups/${this.authGroupId}/storage/buckets/${encodeURIComponent(this.bucketId)}`;
3519
+ }
3520
+ async bearerToken() {
3521
+ const staticKey = this.options.dataStaticKey?.trim() || (this.options.getDataStaticKey ? await this.options.getDataStaticKey() : null)?.trim() || null;
3522
+ if (staticKey) return staticKey;
3523
+ if (this.options.getAccessToken) {
3524
+ const tok = await this.options.getAccessToken();
3525
+ if (tok?.trim()) return tok.trim();
3526
+ }
3527
+ throw new RagableError("No auth token for storage. Provide dataStaticKey or getAccessToken.", 401, { code: "SDK_NO_ACCESS_TOKEN" });
3528
+ }
3529
+ async req(method, path, body) {
3530
+ const token = await this.bearerToken();
3531
+ const headers = new Headers(this.options.headers);
3532
+ headers.set("Authorization", `Bearer ${token}`);
3533
+ if (body !== void 0 && !(body instanceof FormData)) headers.set("Content-Type", "application/json");
3534
+ const res = await this.fetchImpl(`${this.base()}${path}`, {
3535
+ method,
3536
+ headers,
3537
+ body: body instanceof FormData ? body : body !== void 0 ? JSON.stringify(body) : void 0
3538
+ });
3539
+ const payload = await res.json().catch(() => ({}));
3540
+ if (!res.ok) throw new RagableError(payload?.error ?? res.statusText, res.status, payload);
3541
+ return payload;
3542
+ }
3543
+ list(params = {}) {
3544
+ const qs = new URLSearchParams();
3545
+ if (params.prefix) qs.set("prefix", params.prefix);
3546
+ if (params.delimiter) qs.set("delimiter", params.delimiter);
3547
+ if (params.maxResults != null) qs.set("maxResults", String(params.maxResults));
3548
+ if (params.pageToken) qs.set("pageToken", params.pageToken);
3549
+ const q = qs.toString();
3550
+ return this.req("GET", `/contents${q ? `?${q}` : ""}`);
3551
+ }
3552
+ async upload(params) {
3553
+ const token = await this.bearerToken();
3554
+ const headers = new Headers(this.options.headers);
3555
+ headers.set("Authorization", `Bearer ${token}`);
3556
+ const form = new FormData();
3557
+ const raw = params.file instanceof Blob ? params.file : new Blob([new Uint8Array(params.file instanceof ArrayBuffer ? params.file : params.file.buffer)], params.contentType ? { type: params.contentType } : {});
3558
+ const blob = raw;
3559
+ form.set("file", blob, params.fileName ?? "upload");
3560
+ form.set("objectPath", params.objectPath);
3561
+ if (params.cacheControl) form.set("cacheControl", params.cacheControl);
3562
+ const res = await this.fetchImpl(`${this.base()}/upload`, { method: "POST", headers, body: form });
3563
+ const payload = await res.json().catch(() => ({}));
3564
+ if (!res.ok) throw new RagableError(payload?.error ?? res.statusText, res.status, payload);
3565
+ return payload;
3566
+ }
3567
+ download(params) {
3568
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3569
+ if (params.asText != null) qs.set("asText", String(params.asText));
3570
+ if (params.maxTextBytes != null) qs.set("maxTextBytes", String(params.maxTextBytes));
3571
+ return this.req("GET", `/objects/download?${qs}`);
3572
+ }
3573
+ delete(objectPath) {
3574
+ return this.req("DELETE", "/objects", { objectPath });
3575
+ }
3576
+ bulkDelete(objectPaths) {
3577
+ return this.req("POST", "/objects/delete-bulk", { objectPaths });
3578
+ }
3579
+ getSignedUploadUrl(params) {
3580
+ return this.req("POST", "/signed-upload-url", params);
3581
+ }
3582
+ getSignedDownloadUrl(params) {
3583
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3584
+ if (params.expiresInSeconds != null) qs.set("expiresInSeconds", String(params.expiresInSeconds));
3585
+ return this.req("GET", `/signed-download-url?${qs}`);
3586
+ }
3587
+ copy(params) {
3588
+ return this.req("POST", "/objects/copy", params);
3589
+ }
3590
+ move(params) {
3591
+ return this.req("POST", "/objects/move", params);
3592
+ }
3593
+ createFolder(folderPath) {
3594
+ return this.req("POST", "/folders", { folderPath });
3595
+ }
3596
+ deleteFolder(folderPath) {
3597
+ return this.req("DELETE", "/folders", { folderPath });
3598
+ }
3599
+ getMetadata(objectPath) {
3600
+ const qs = new URLSearchParams({ objectPath });
3601
+ return this.req("GET", `/objects/metadata?${qs}`);
3602
+ }
3603
+ };
3604
+ var RagableBrowserStorageClient = class {
3605
+ constructor(options, fetchImpl) {
3606
+ this.options = options;
3607
+ this.fetchImpl = fetchImpl;
3608
+ }
3609
+ from(bucketId) {
3610
+ return new BrowserStorageBucketClient(this.options, this.fetchImpl, bucketId);
3611
+ }
3612
+ };
3294
3613
  var RagableBrowserAgentsClient = class {
3295
3614
  constructor(options) {
3296
3615
  this.options = options;
@@ -3355,6 +3674,58 @@ var RagableBrowserAgentsClient = class {
3355
3674
  }
3356
3675
  yield* readSseStream(streamBody);
3357
3676
  }
3677
+ /**
3678
+ * Stream a project agent defined in `agents/*.json` using the same result
3679
+ * shape as `client.ai.streamText`. Preferred over {@link chatStreamByName}
3680
+ * and {@link runChatStreamByName} — those remain for back-compat only.
3681
+ *
3682
+ * ```ts
3683
+ * const { textStream, text } = client.agents.run("support", {
3684
+ * messages: [{ role: "user", content: "I can't log in" }],
3685
+ * });
3686
+ * for await (const delta of textStream) process.stdout.write(delta);
3687
+ * console.log(await text);
3688
+ * ```
3689
+ */
3690
+ run(agentName, params) {
3691
+ const source = this.runStreamParts(agentName, params);
3692
+ return createStreamResultFromParts(source);
3693
+ }
3694
+ async *runStreamParts(agentName, params) {
3695
+ const { messages } = params;
3696
+ if (!Array.isArray(messages) || messages.length === 0) {
3697
+ throw new RagableError(
3698
+ "agents.run requires at least one message",
3699
+ 400,
3700
+ { code: "SDK_AGENTS_RUN_EMPTY_MESSAGES" }
3701
+ );
3702
+ }
3703
+ const last = messages[messages.length - 1];
3704
+ if (!last || last.role !== "user") {
3705
+ throw new RagableError(
3706
+ 'agents.run: the final message must have role "user"',
3707
+ 400,
3708
+ { code: "SDK_AGENTS_RUN_INVALID_LAST_MESSAGE" }
3709
+ );
3710
+ }
3711
+ const history = messages.slice(0, -1).filter((m) => m.role === "user" || m.role === "assistant").map((m) => ({
3712
+ role: m.role,
3713
+ content: m.content
3714
+ }));
3715
+ const events = this.chatStreamByName(agentName, {
3716
+ message: last.content,
3717
+ ...history.length > 0 ? { history } : {},
3718
+ ...params.signal !== void 0 ? { signal: params.signal } : {}
3719
+ });
3720
+ for await (const event of events) {
3721
+ const mapped = mapAgentEvent(event);
3722
+ if (mapped) yield mapped;
3723
+ }
3724
+ }
3725
+ /**
3726
+ * @deprecated Use {@link run} for new code. This method is kept for
3727
+ * back-compat with the original chat-stream DX.
3728
+ */
3358
3729
  async *chatStreamByName(agentName, params) {
3359
3730
  const headers = new Headers(this.options.headers);
3360
3731
  headers.set("Content-Type", "application/json");
@@ -3383,8 +3754,9 @@ var RagableBrowserAgentsClient = class {
3383
3754
  yield* readSseStream(response.body);
3384
3755
  }
3385
3756
  /**
3386
- * Stream a project agent (`/agents/*.json`) with callbacks; returns the final `done` payload
3387
- * plus streamed assistant text. Prefer this over manual `for await` when building chat UIs.
3757
+ * @deprecated Use {@link run} for new code. Returns the legacy callback-based
3758
+ * result type leaking server internals; the new Vercel-style API exposes
3759
+ * `textStream` / `fullStream` / promises for `text`, `usage`, `finishReason`.
3388
3760
  */
3389
3761
  async runChatStreamByName(agentName, params, handlers = {}) {
3390
3762
  return runAgentChatStream(this.chatStreamByName(agentName, params), handlers, {
@@ -3481,9 +3853,11 @@ var RagableBrowserAgentsClient = class {
3481
3853
  var RagableBrowser = class {
3482
3854
  constructor(options) {
3483
3855
  __publicField(this, "agents");
3856
+ __publicField(this, "ai");
3484
3857
  __publicField(this, "auth");
3485
3858
  __publicField(this, "database");
3486
3859
  __publicField(this, "db");
3860
+ __publicField(this, "storage");
3487
3861
  __publicField(this, "transport");
3488
3862
  __publicField(this, "_ragableAuth");
3489
3863
  /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
@@ -3514,6 +3888,13 @@ var RagableBrowser = class {
3514
3888
  this._ragableAuth = null;
3515
3889
  }
3516
3890
  this.agents = new RagableBrowserAgentsClient(options);
3891
+ this.ai = new RagableBrowserAiClient({
3892
+ organizationId: options.organizationId,
3893
+ ...options.websiteId !== void 0 ? { websiteId: options.websiteId } : {},
3894
+ ...options.fetch !== void 0 ? { fetch: options.fetch } : {},
3895
+ ...options.headers !== void 0 ? { headers: options.headers } : {},
3896
+ apiBase: normalizeBrowserApiBase()
3897
+ });
3517
3898
  this.auth = new RagableBrowserAuthClient(options, this._ragableAuth);
3518
3899
  this.database = new RagableBrowserDatabaseClient(
3519
3900
  options,
@@ -3521,6 +3902,7 @@ var RagableBrowser = class {
3521
3902
  );
3522
3903
  this.database._setTransport(this.transport);
3523
3904
  this.db = this.database;
3905
+ this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch));
3524
3906
  }
3525
3907
  destroy() {
3526
3908
  this._ragableAuth?.destroy();
@@ -3531,246 +3913,14 @@ function createBrowserClient(options) {
3531
3913
  }
3532
3914
  var createRagableBrowserClient = createBrowserClient;
3533
3915
 
3534
- // src/rag.ts
3535
- function formatRetrievalContext(results, options = {}) {
3536
- const header = options.header ?? "Relevant passages:\n";
3537
- const separator = options.separator ?? "\n\n";
3538
- const minScore = options.minScore;
3539
- let filtered = results;
3540
- if (typeof minScore === "number") {
3541
- filtered = results.filter((r) => r.score >= minScore);
3542
- }
3543
- const blocks = filtered.map((r, i) => {
3544
- const scoreSuffix = options.includeScores === true ? ` (score: ${r.score.toFixed(4)})` : "";
3545
- return `[${i + 1}]${scoreSuffix}
3546
- ${r.content.trim()}`;
3547
- });
3548
- let text = (blocks.length > 0 ? header : "") + blocks.join(separator);
3549
- if (typeof options.maxChars === "number" && text.length > options.maxChars) {
3550
- text = text.slice(0, options.maxChars).trimEnd() + "\n\u2026";
3551
- }
3552
- return text;
3553
- }
3554
- function createRagPipeline(client, options) {
3555
- const { indexId } = options;
3556
- return {
3557
- indexId,
3558
- ingestText(params) {
3559
- return client.shift.documents.create(indexId, params);
3560
- },
3561
- ingestFile(params) {
3562
- return client.shift.documents.upload(indexId, params);
3563
- },
3564
- search(params) {
3565
- return client.shift.search(indexId, params);
3566
- },
3567
- async retrieve(params) {
3568
- const { format: formatOpts, ...searchParams } = params;
3569
- const { results } = await client.shift.search(indexId, searchParams);
3570
- const context = formatRetrievalContext(results, formatOpts ?? {});
3571
- return { results, context };
3572
- }
3573
- };
3574
- }
3575
-
3576
- // src/storage.ts
3577
- function normalizeUploadFile2(file, contentType) {
3578
- if (file instanceof Blob) return file;
3579
- const u8 = file instanceof ArrayBuffer ? new Uint8Array(file) : new Uint8Array(file);
3580
- return new Blob([u8.buffer], contentType ? { type: contentType } : {});
3581
- }
3582
- var StorageClient = class {
3583
- constructor(client) {
3584
- this.client = client;
3585
- /**
3586
- * Bucket-level CRUD — list, create and delete buckets for this organisation.
3587
- */
3588
- __publicField(this, "buckets");
3589
- this.buckets = {
3590
- list: async (params) => {
3591
- const qs = new URLSearchParams();
3592
- if (params?.q) qs.set("q", params.q);
3593
- if (params?.status) qs.set("status", params.status);
3594
- if (params?.sort) qs.set("sort", params.sort);
3595
- const query = qs.toString();
3596
- return this.client.request(
3597
- `/v1/storage/buckets${query ? `?${query}` : ""}`
3598
- );
3599
- },
3600
- create: async (name) => {
3601
- return this.client.request("/v1/storage/buckets", {
3602
- method: "POST",
3603
- body: { name }
3604
- });
3605
- },
3606
- delete: async (bucketId) => {
3607
- return this.client.request(
3608
- `/v1/storage/buckets/${encodeURIComponent(bucketId)}`,
3609
- { method: "DELETE" }
3610
- );
3611
- }
3612
- };
3613
- }
3614
- /**
3615
- * Returns a {@link StorageBucketClient} scoped to the given bucket ID.
3616
- *
3617
- * All object operations (upload, download, list, copy, move, signed URLs, …)
3618
- * are performed through the returned client.
3619
- *
3620
- * @param bucketId The Ragable bucket ID obtained from `buckets.list()` or `buckets.create()`.
3621
- */
3622
- from(bucketId) {
3623
- const { client } = this;
3624
- const base = `/v1/storage/buckets/${encodeURIComponent(bucketId)}`;
3625
- return {
3626
- list: async (params) => {
3627
- const qs = new URLSearchParams();
3628
- if (params?.prefix) qs.set("prefix", params.prefix);
3629
- if (params?.delimiter) qs.set("delimiter", params.delimiter);
3630
- if (params?.maxResults != null)
3631
- qs.set("maxResults", String(params.maxResults));
3632
- if (params?.pageToken) qs.set("pageToken", params.pageToken);
3633
- const query = qs.toString();
3634
- return client.request(
3635
- `${base}/contents${query ? `?${query}` : ""}`
3636
- );
3637
- },
3638
- createFolder: async (folderPath) => {
3639
- return client.request(
3640
- `${base}/folders`,
3641
- { method: "POST", body: { folderPath } }
3642
- );
3643
- },
3644
- deleteFolder: async (folderPath) => {
3645
- return client.request(
3646
- `${base}/folders`,
3647
- { method: "DELETE", body: { folderPath } }
3648
- );
3649
- },
3650
- upload: async (params) => {
3651
- const formData = new FormData();
3652
- const blob = normalizeUploadFile2(params.file, params.contentType);
3653
- const fileName = params.fileName ?? "upload";
3654
- formData.set("file", blob, fileName);
3655
- formData.set("objectPath", params.objectPath);
3656
- if (params.cacheControl) {
3657
- formData.set("cacheControl", params.cacheControl);
3658
- }
3659
- return client.request(`${base}/upload`, {
3660
- method: "POST",
3661
- body: formData
3662
- });
3663
- },
3664
- delete: async (objectPath) => {
3665
- return client.request(
3666
- `${base}/objects`,
3667
- { method: "DELETE", body: { objectPath } }
3668
- );
3669
- },
3670
- bulkDelete: async (objectPaths) => {
3671
- return client.request(
3672
- `${base}/objects/delete-bulk`,
3673
- { method: "POST", body: { objectPaths } }
3674
- );
3675
- },
3676
- getMetadata: async (objectPath) => {
3677
- const qs = new URLSearchParams({ objectPath });
3678
- return client.request(
3679
- `${base}/objects/metadata?${qs}`
3680
- );
3681
- },
3682
- updateMetadata: async (params) => {
3683
- return client.request(
3684
- `${base}/objects/metadata`,
3685
- { method: "PATCH", body: params }
3686
- );
3687
- },
3688
- download: async (params) => {
3689
- const qs = new URLSearchParams({ objectPath: params.objectPath });
3690
- if (params.asText != null) qs.set("asText", String(params.asText));
3691
- if (params.maxTextBytes != null)
3692
- qs.set("maxTextBytes", String(params.maxTextBytes));
3693
- return client.request(
3694
- `${base}/objects/download?${qs}`
3695
- );
3696
- },
3697
- copy: async (params) => {
3698
- return client.request(`${base}/objects/copy`, { method: "POST", body: params });
3699
- },
3700
- move: async (params) => {
3701
- return client.request(`${base}/objects/move`, { method: "POST", body: params });
3702
- },
3703
- getSignedUploadUrl: async (params) => {
3704
- return client.request(
3705
- `${base}/signed-upload-url`,
3706
- { method: "POST", body: params }
3707
- );
3708
- },
3709
- getSignedDownloadUrl: async (params) => {
3710
- const qs = new URLSearchParams({ objectPath: params.objectPath });
3711
- if (params.expiresInSeconds != null)
3712
- qs.set("expiresInSeconds", String(params.expiresInSeconds));
3713
- return client.request(
3714
- `${base}/signed-download-url?${qs}`
3715
- );
3716
- },
3717
- getSettings: async () => {
3718
- return client.request(`${base}/settings`);
3719
- },
3720
- updateSettings: async (params) => {
3721
- return client.request(`${base}/settings`, {
3722
- method: "PATCH",
3723
- body: params
3724
- });
3725
- }
3726
- };
3727
- }
3728
- };
3729
-
3730
3916
  // src/index.ts
3731
- var Ragable = class {
3732
- constructor(options) {
3733
- __publicField(this, "shift");
3734
- __publicField(this, "agents");
3735
- __publicField(this, "storage");
3736
- __publicField(this, "infrastructure");
3737
- const client = new RagableRequestClient(options);
3738
- this.shift = new ShiftClient(client);
3739
- this.agents = new AgentsClient(client);
3740
- this.storage = new StorageClient(client);
3741
- this.infrastructure = {
3742
- shift: this.shift
3743
- };
3744
- }
3745
- };
3746
- function isServerClientOptions(o) {
3747
- return typeof o === "object" && o !== null && "apiKey" in o && typeof o.apiKey === "string" && o.apiKey.length > 0;
3748
- }
3749
3917
  function createClient(options) {
3750
- if (isServerClientOptions(options)) {
3751
- if (typeof options === "object" && options !== null && "organizationId" in options && typeof options.organizationId === "string") {
3752
- console.warn(
3753
- "[@ragable/sdk] createClient: `apiKey` is set, so the server client is returned. It has no `database` or `auth` \u2014 only `agents` and `shift`. For `db.collections.<name>` / `database.from()` / `auth.*`, use the browser client without `apiKey` (e.g. createClient({ organizationId, authGroupId, databaseInstanceId, ... }))."
3754
- );
3755
- }
3756
- return new Ragable(options);
3757
- }
3758
- if (typeof options === "object" && options !== null && "organizationId" in options && typeof options.organizationId === "string") {
3759
- return createBrowserClient(
3760
- options
3761
- );
3762
- }
3763
- throw new Error(
3764
- "createClient(options) requires apiKey (server) or organizationId (browser)"
3765
- );
3766
- }
3767
- function createRagableServerClient(options) {
3768
- return new Ragable(options);
3918
+ return createBrowserClient(options);
3769
3919
  }
3770
3920
  // Annotate the CommonJS export names for ESM import in node:
3771
3921
  0 && (module.exports = {
3772
- AgentsClient,
3773
3922
  AuthBroadcastChannel,
3923
+ BrowserStorageBucketClient,
3774
3924
  CookieStorageAdapter,
3775
3925
  DEFAULT_RAGABLE_API_BASE,
3776
3926
  LocalStorageAdapter,
@@ -3787,43 +3937,42 @@ function createRagableServerClient(options) {
3787
3937
  PostgrestUpdateRootBuilder,
3788
3938
  PostgrestUpsertReturningBuilder,
3789
3939
  PostgrestUpsertRootBuilder,
3790
- Ragable,
3791
3940
  RagableAbortError,
3792
3941
  RagableAuth,
3793
3942
  RagableBrowser,
3794
3943
  RagableBrowserAgentsClient,
3944
+ RagableBrowserAiClient,
3795
3945
  RagableBrowserAuthClient,
3796
3946
  RagableBrowserDatabaseClient,
3947
+ RagableBrowserStorageClient,
3797
3948
  RagableError,
3798
3949
  RagableNetworkError,
3799
- RagableRequestClient,
3800
3950
  RagableSdkError,
3801
3951
  RagableTimeoutError,
3802
3952
  SessionStorageAdapter,
3803
- ShiftClient,
3804
- StorageClient,
3805
3953
  Transport,
3806
3954
  asPostgrestResponse,
3807
3955
  assertPostgrestSuccess,
3808
3956
  bindFetch,
3957
+ buildInferenceRequestBody,
3809
3958
  collectAssistantTextFromUiSegments,
3810
3959
  collectionRecordToRowWithMeta,
3811
3960
  collectionRecordsToRowWithMeta,
3812
3961
  createBrowserClient,
3813
3962
  createClient,
3814
- createRagPipeline,
3815
3963
  createRagableBrowserClient,
3816
- createRagableServerClient,
3964
+ createStreamResultFromParts,
3817
3965
  detectStorage,
3818
3966
  effectiveDataAuth,
3819
3967
  extractErrorMessage,
3820
3968
  finalizeAgentChatUiTurn,
3821
3969
  foldAgentStreamIntoUiSegments,
3822
3970
  formatPostgrestError,
3823
- formatRetrievalContext,
3824
3971
  formatSdkError,
3825
3972
  generateIdempotencyKey,
3826
3973
  isIncompleteAgentStreamError,
3974
+ mapAgentEvent,
3975
+ mapFireworksChunk,
3827
3976
  normalizeBrowserApiBase,
3828
3977
  parseAgentStreamAgentInfo,
3829
3978
  parseAgentStreamDone,