@reverbia/sdk 1.0.0-next.20260109140427 → 1.0.0-next.20260109180912

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.
@@ -1439,10 +1439,7 @@ function useChat(options) {
1439
1439
  continue;
1440
1440
  }
1441
1441
  if (chunk && typeof chunk === "object") {
1442
- const { content: contentDelta, thinking: thinkingDelta } = strategy.processStreamChunk(
1443
- chunk,
1444
- accumulator
1445
- );
1442
+ const { content: contentDelta, thinking: thinkingDelta } = strategy.processStreamChunk(chunk, accumulator);
1446
1443
  if (contentDelta) {
1447
1444
  if (onData) onData(contentDelta);
1448
1445
  if (globalOnData) globalOnData(contentDelta);
@@ -1475,7 +1472,11 @@ function useChat(options) {
1475
1472
  }
1476
1473
  const response = strategy.buildFinalResponse(accumulator);
1477
1474
  if (accumulator.toolCalls.size > 0) {
1478
- console.log("[Tool Debug] Found", accumulator.toolCalls.size, "tool calls");
1475
+ console.log(
1476
+ "[Tool Debug] Found",
1477
+ accumulator.toolCalls.size,
1478
+ "tool calls"
1479
+ );
1479
1480
  const executorMap = createToolExecutorMap(tools);
1480
1481
  const toolCallsToExecute = [];
1481
1482
  for (const toolCall of accumulator.toolCalls.values()) {
@@ -1485,7 +1486,10 @@ function useChat(options) {
1485
1486
  console.log("[Tool Debug] Will auto-execute:", toolCall.name);
1486
1487
  toolCallsToExecute.push(toolCall);
1487
1488
  } else {
1488
- console.log("[Tool Debug] Emitting onToolCall event for:", toolCall.name);
1489
+ console.log(
1490
+ "[Tool Debug] Emitting onToolCall event for:",
1491
+ toolCall.name
1492
+ );
1489
1493
  if (onToolCall) {
1490
1494
  onToolCall({
1491
1495
  id: toolCall.id,
@@ -1499,7 +1503,11 @@ function useChat(options) {
1499
1503
  }
1500
1504
  }
1501
1505
  if (toolCallsToExecute.length > 0) {
1502
- console.log("[Tool Debug] Executing", toolCallsToExecute.length, "tools");
1506
+ console.log(
1507
+ "[Tool Debug] Executing",
1508
+ toolCallsToExecute.length,
1509
+ "tools"
1510
+ );
1503
1511
  if (onThinking || globalOnThinking) {
1504
1512
  const toolInfo = toolCallsToExecute.map((tc) => {
1505
1513
  try {
@@ -1529,7 +1537,12 @@ Executing tool: ${toolInfo}
1529
1537
  toolCall,
1530
1538
  executorConfig.executor
1531
1539
  );
1532
- console.log("[Tool Debug] Tool execution result for", toolCall.name, ":", { result, error });
1540
+ console.log(
1541
+ "[Tool Debug] Tool execution result for",
1542
+ toolCall.name,
1543
+ ":",
1544
+ { result, error }
1545
+ );
1533
1546
  return {
1534
1547
  id: toolCall.id,
1535
1548
  name: toolCall.name,
@@ -1538,7 +1551,10 @@ Executing tool: ${toolInfo}
1538
1551
  };
1539
1552
  })
1540
1553
  );
1541
- console.log("[Tool Debug] All tools executed, results:", executionResults.length);
1554
+ console.log(
1555
+ "[Tool Debug] All tools executed, results:",
1556
+ executionResults.length
1557
+ );
1542
1558
  if (onThinking || globalOnThinking) {
1543
1559
  const resultsText = executionResults.map((r) => {
1544
1560
  if (r.error) {
@@ -1574,8 +1590,14 @@ Executing tool: ${toolInfo}
1574
1590
  tool_call_id: execResult.id
1575
1591
  });
1576
1592
  }
1577
- const continuationMessages = [...messagesWithContext, ...toolResultMessages];
1578
- console.log("[Tool Debug] Continuation messages:", JSON.stringify(continuationMessages, null, 2));
1593
+ const continuationMessages = [
1594
+ ...messagesWithContext,
1595
+ ...toolResultMessages
1596
+ ];
1597
+ console.log(
1598
+ "[Tool Debug] Continuation messages:",
1599
+ JSON.stringify(continuationMessages, null, 2)
1600
+ );
1579
1601
  const continuationRequestBody = strategy.buildRequestBody({
1580
1602
  messages: continuationMessages,
1581
1603
  model,
@@ -1612,10 +1634,7 @@ Executing tool: ${toolInfo}
1612
1634
  continue;
1613
1635
  }
1614
1636
  if (chunk && typeof chunk === "object") {
1615
- const { content: contentDelta, thinking: thinkingDelta } = strategy.processStreamChunk(
1616
- chunk,
1617
- continuationAccumulator
1618
- );
1637
+ const { content: contentDelta, thinking: thinkingDelta } = strategy.processStreamChunk(chunk, continuationAccumulator);
1619
1638
  if (contentDelta) {
1620
1639
  if (onData) onData(contentDelta);
1621
1640
  if (globalOnData) globalOnData(contentDelta);
@@ -1626,11 +1645,19 @@ Executing tool: ${toolInfo}
1626
1645
  }
1627
1646
  }
1628
1647
  }
1629
- console.log("[Tool Debug] Continuation stream complete - accumulated content:", continuationAccumulator.content);
1630
- console.log("[Tool Debug] Continuation stream complete - accumulated thinking:", continuationAccumulator.thinking);
1648
+ console.log(
1649
+ "[Tool Debug] Continuation stream complete - accumulated content:",
1650
+ continuationAccumulator.content
1651
+ );
1652
+ console.log(
1653
+ "[Tool Debug] Continuation stream complete - accumulated thinking:",
1654
+ continuationAccumulator.thinking
1655
+ );
1631
1656
  } catch (streamErr) {
1632
1657
  if (isAbortError(streamErr) || abortController.signal.aborted) {
1633
- const partialResponse = strategy.buildFinalResponse(continuationAccumulator);
1658
+ const partialResponse = strategy.buildFinalResponse(
1659
+ continuationAccumulator
1660
+ );
1634
1661
  return {
1635
1662
  data: partialResponse,
1636
1663
  error: "Request aborted"
@@ -1639,7 +1666,9 @@ Executing tool: ${toolInfo}
1639
1666
  throw streamErr;
1640
1667
  }
1641
1668
  if (abortController.signal.aborted) {
1642
- const partialResponse = strategy.buildFinalResponse(continuationAccumulator);
1669
+ const partialResponse = strategy.buildFinalResponse(
1670
+ continuationAccumulator
1671
+ );
1643
1672
  return {
1644
1673
  data: partialResponse,
1645
1674
  error: "Request aborted"
@@ -1648,7 +1677,9 @@ Executing tool: ${toolInfo}
1648
1677
  if (sseError) {
1649
1678
  throw sseError;
1650
1679
  }
1651
- const finalResponse = strategy.buildFinalResponse(continuationAccumulator);
1680
+ const finalResponse = strategy.buildFinalResponse(
1681
+ continuationAccumulator
1682
+ );
1652
1683
  if (onFinish) {
1653
1684
  onFinish(finalResponse);
1654
1685
  }
@@ -1681,7 +1712,16 @@ Executing tool: ${toolInfo}
1681
1712
  }
1682
1713
  }
1683
1714
  },
1684
- [getToken, baseUrl, globalOnData, globalOnThinking, onFinish, onError, onToolCall, defaultApiType]
1715
+ [
1716
+ getToken,
1717
+ baseUrl,
1718
+ globalOnData,
1719
+ globalOnThinking,
1720
+ onFinish,
1721
+ onError,
1722
+ onToolCall,
1723
+ defaultApiType
1724
+ ]
1685
1725
  );
1686
1726
  return {
1687
1727
  isLoading,
@@ -2408,6 +2448,36 @@ function finalizeThoughtProcess(thoughtProcess) {
2408
2448
  (phase, idx) => idx === thoughtProcess.length - 1 ? { ...phase, status: "completed" } : phase
2409
2449
  );
2410
2450
  }
2451
+ function extractUserMessageFromMessages(messages) {
2452
+ if (!messages || messages.length === 0) {
2453
+ return null;
2454
+ }
2455
+ const userMessages = messages.filter((m) => m.role === "user");
2456
+ const lastUserMessage = userMessages[userMessages.length - 1];
2457
+ if (!lastUserMessage || !lastUserMessage.content) {
2458
+ return null;
2459
+ }
2460
+ const textParts = [];
2461
+ const files = [];
2462
+ for (const part of lastUserMessage.content) {
2463
+ if (part.type === "text" && part.text) {
2464
+ textParts.push(part.text);
2465
+ } else if (part.type === "image_url" && part.image_url?.url) {
2466
+ files.push({
2467
+ id: `img_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
2468
+ name: "image",
2469
+ type: "image/unknown",
2470
+ size: 0,
2471
+ url: part.image_url.url
2472
+ });
2473
+ }
2474
+ }
2475
+ const content = textParts.join("\n");
2476
+ return {
2477
+ content,
2478
+ files: files.length > 0 ? files : void 0
2479
+ };
2480
+ }
2411
2481
 
2412
2482
  // src/lib/db/chat/operations.ts
2413
2483
  import { Q } from "@nozbe/watermelondb";
@@ -2930,9 +3000,8 @@ function useChatStorage(options) {
2930
3000
  const sendMessage = useCallback2(
2931
3001
  async (args) => {
2932
3002
  const {
2933
- content,
3003
+ messages,
2934
3004
  model,
2935
- messages: providedMessages,
2936
3005
  includeHistory = true,
2937
3006
  maxHistoryMessages = 50,
2938
3007
  files,
@@ -2956,6 +3025,15 @@ function useChatStorage(options) {
2956
3025
  apiType: requestApiType,
2957
3026
  writeFile
2958
3027
  } = args;
3028
+ const extracted = extractUserMessageFromMessages(messages);
3029
+ if (!extracted || !extracted.content) {
3030
+ return {
3031
+ data: null,
3032
+ error: "No user message found in messages array"
3033
+ };
3034
+ }
3035
+ const contentForStorage = extracted.content;
3036
+ const filesForStorage = files ?? extracted.files;
2959
3037
  let convId;
2960
3038
  try {
2961
3039
  convId = await ensureConversation();
@@ -2966,33 +3044,18 @@ function useChatStorage(options) {
2966
3044
  };
2967
3045
  }
2968
3046
  let messagesToSend = [];
2969
- if (includeHistory && !providedMessages) {
3047
+ if (includeHistory) {
2970
3048
  const storedMessages = await getMessages(convId);
2971
3049
  const validMessages = storedMessages.filter((msg) => !msg.error);
2972
3050
  const limitedMessages = validMessages.slice(-maxHistoryMessages);
2973
- messagesToSend = limitedMessages.map(storedToLlmapiMessage);
2974
- } else if (providedMessages) {
2975
- messagesToSend = providedMessages;
2976
- }
2977
- const userMessageContent = [
2978
- { type: "text", text: content }
2979
- ];
2980
- if (files && files.length > 0) {
2981
- for (const file of files) {
2982
- if (file.url && file.type.startsWith("image/")) {
2983
- userMessageContent.push({
2984
- type: "image_url",
2985
- image_url: { url: file.url }
2986
- });
2987
- }
2988
- }
3051
+ messagesToSend = [
3052
+ ...limitedMessages.map(storedToLlmapiMessage),
3053
+ ...messages
3054
+ ];
3055
+ } else {
3056
+ messagesToSend = [...messages];
2989
3057
  }
2990
- const userMessage = {
2991
- role: "user",
2992
- content: userMessageContent
2993
- };
2994
- messagesToSend.push(userMessage);
2995
- const sanitizedFiles = files?.map((file) => ({
3058
+ const sanitizedFiles = filesForStorage?.map((file) => ({
2996
3059
  id: file.id,
2997
3060
  name: file.name,
2998
3061
  type: file.type,
@@ -3005,7 +3068,7 @@ function useChatStorage(options) {
3005
3068
  storedUserMessage = await createMessageOp(storageCtx, {
3006
3069
  conversationId: convId,
3007
3070
  role: "user",
3008
- content,
3071
+ content: contentForStorage,
3009
3072
  files: sanitizedFiles,
3010
3073
  model
3011
3074
  });
@@ -6478,11 +6541,17 @@ function DropboxAuthProvider({
6478
6541
  if (!isConfigured) return;
6479
6542
  const handleCallback = async () => {
6480
6543
  if (isDropboxCallback()) {
6481
- const result = await handleDropboxCallback(callbackPath, apiClient, walletAddress);
6544
+ const result = await handleDropboxCallback(
6545
+ callbackPath,
6546
+ apiClient,
6547
+ walletAddress
6548
+ );
6482
6549
  if (result.ok) {
6483
6550
  setAccessToken(result.data);
6484
6551
  } else {
6485
- console.error(`Dropbox OAuth failed: ${result.error.code} - ${result.error.message}`);
6552
+ console.error(
6553
+ `Dropbox OAuth failed: ${result.error.code} - ${result.error.message}`
6554
+ );
6486
6555
  }
6487
6556
  }
6488
6557
  };
@@ -6508,7 +6577,14 @@ function DropboxAuthProvider({
6508
6577
  return storedToken;
6509
6578
  }
6510
6579
  return startDropboxAuth(appKey, callbackPath);
6511
- }, [accessToken, appKey, callbackPath, isConfigured, apiClient, walletAddress]);
6580
+ }, [
6581
+ accessToken,
6582
+ appKey,
6583
+ callbackPath,
6584
+ isConfigured,
6585
+ apiClient,
6586
+ walletAddress
6587
+ ]);
6512
6588
  const logout = useCallback10(async () => {
6513
6589
  await revokeDropboxToken(apiClient, walletAddress);
6514
6590
  setAccessToken(null);
@@ -6885,11 +6961,17 @@ function GoogleDriveAuthProvider({
6885
6961
  if (!isConfigured) return;
6886
6962
  const handleCallback = async () => {
6887
6963
  if (isGoogleDriveCallback()) {
6888
- const result = await handleGoogleDriveCallback(callbackPath, apiClient, walletAddress);
6964
+ const result = await handleGoogleDriveCallback(
6965
+ callbackPath,
6966
+ apiClient,
6967
+ walletAddress
6968
+ );
6889
6969
  if (result.ok) {
6890
6970
  setAccessToken(result.data);
6891
6971
  } else {
6892
- console.error(`Google Drive OAuth failed: ${result.error.code} - ${result.error.message}`);
6972
+ console.error(
6973
+ `Google Drive OAuth failed: ${result.error.code} - ${result.error.message}`
6974
+ );
6893
6975
  }
6894
6976
  }
6895
6977
  };
@@ -6909,13 +6991,23 @@ function GoogleDriveAuthProvider({
6909
6991
  if (accessToken) {
6910
6992
  return accessToken;
6911
6993
  }
6912
- const storedToken = await getGoogleDriveAccessToken(apiClient, walletAddress);
6994
+ const storedToken = await getGoogleDriveAccessToken(
6995
+ apiClient,
6996
+ walletAddress
6997
+ );
6913
6998
  if (storedToken) {
6914
6999
  setAccessToken(storedToken);
6915
7000
  return storedToken;
6916
7001
  }
6917
7002
  return startGoogleDriveAuth(clientId, callbackPath);
6918
- }, [accessToken, clientId, callbackPath, isConfigured, apiClient, walletAddress]);
7003
+ }, [
7004
+ accessToken,
7005
+ clientId,
7006
+ callbackPath,
7007
+ isConfigured,
7008
+ apiClient,
7009
+ walletAddress
7010
+ ]);
6919
7011
  const logout = useCallback12(async () => {
6920
7012
  await revokeGoogleDriveToken(apiClient, walletAddress);
6921
7013
  setAccessToken(null);
@@ -8001,7 +8093,9 @@ function BackupAuthProvider({
8001
8093
  if (result.ok) {
8002
8094
  setDropboxToken(result.data);
8003
8095
  } else {
8004
- console.error(`Dropbox OAuth failed: ${result.error.code} - ${result.error.message}`);
8096
+ console.error(
8097
+ `Dropbox OAuth failed: ${result.error.code} - ${result.error.message}`
8098
+ );
8005
8099
  }
8006
8100
  }
8007
8101
  };
@@ -8019,7 +8113,9 @@ function BackupAuthProvider({
8019
8113
  if (result.ok) {
8020
8114
  setGoogleToken(result.data);
8021
8115
  } else {
8022
- console.error(`Google Drive OAuth failed: ${result.error.code} - ${result.error.message}`);
8116
+ console.error(
8117
+ `Google Drive OAuth failed: ${result.error.code} - ${result.error.message}`
8118
+ );
8023
8119
  }
8024
8120
  }
8025
8121
  };
@@ -8042,7 +8138,13 @@ function BackupAuthProvider({
8042
8138
  return storedToken;
8043
8139
  }
8044
8140
  return startDropboxAuth(dropboxAppKey, dropboxCallbackPath);
8045
- }, [dropboxAppKey, dropboxCallbackPath, isDropboxConfigured, apiClient, walletAddress]);
8141
+ }, [
8142
+ dropboxAppKey,
8143
+ dropboxCallbackPath,
8144
+ isDropboxConfigured,
8145
+ apiClient,
8146
+ walletAddress
8147
+ ]);
8046
8148
  const logoutDropbox = useCallback16(async () => {
8047
8149
  await revokeDropboxToken(apiClient, walletAddress);
8048
8150
  setDropboxToken(null);
@@ -8058,13 +8160,22 @@ function BackupAuthProvider({
8058
8160
  if (!isGoogleConfigured || !googleClientId) {
8059
8161
  throw new Error("Google Drive is not configured");
8060
8162
  }
8061
- const storedToken = await getGoogleDriveAccessToken(apiClient, walletAddress);
8163
+ const storedToken = await getGoogleDriveAccessToken(
8164
+ apiClient,
8165
+ walletAddress
8166
+ );
8062
8167
  if (storedToken) {
8063
8168
  setGoogleToken(storedToken);
8064
8169
  return storedToken;
8065
8170
  }
8066
8171
  return startGoogleDriveAuth(googleClientId, googleCallbackPath);
8067
- }, [googleClientId, googleCallbackPath, isGoogleConfigured, apiClient, walletAddress]);
8172
+ }, [
8173
+ googleClientId,
8174
+ googleCallbackPath,
8175
+ isGoogleConfigured,
8176
+ apiClient,
8177
+ walletAddress
8178
+ ]);
8068
8179
  const logoutGoogle = useCallback16(async () => {
8069
8180
  await revokeGoogleDriveToken(apiClient, walletAddress);
8070
8181
  setGoogleToken(null);
@@ -8109,7 +8220,14 @@ function BackupAuthProvider({
8109
8220
  isGoogleConfigured ? logoutGoogle() : Promise.resolve(),
8110
8221
  isIcloudConfigured ? logoutIcloud() : Promise.resolve()
8111
8222
  ]);
8112
- }, [isDropboxConfigured, isGoogleConfigured, isIcloudConfigured, logoutDropbox, logoutGoogle, logoutIcloud]);
8223
+ }, [
8224
+ isDropboxConfigured,
8225
+ isGoogleConfigured,
8226
+ isIcloudConfigured,
8227
+ logoutDropbox,
8228
+ logoutGoogle,
8229
+ logoutIcloud
8230
+ ]);
8113
8231
  const dropboxState = {
8114
8232
  accessToken: dropboxToken,
8115
8233
  isAuthenticated: !!dropboxToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reverbia/sdk",
3
- "version": "1.0.0-next.20260109140427",
3
+ "version": "1.0.0-next.20260109180912",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -100,7 +100,9 @@
100
100
  "typedoc": "^0.28.14",
101
101
  "typedoc-plugin-frontmatter": "^1.3.0",
102
102
  "typedoc-plugin-markdown": "^4.9.0",
103
+ "typedoc-plugin-remark": "^2.0.1",
103
104
  "typescript": "^5.9.3",
105
+ "unist-util-visit": "^5.0.0",
104
106
  "vitest": "^4.0.14"
105
107
  },
106
108
  "peerDependencies": {