@anuma/sdk 6.31.0 → 6.31.1
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/expo/index.cjs +190 -11
- package/dist/expo/index.mjs +190 -11
- package/dist/react/index.cjs +176 -9
- package/dist/react/index.d.mts +2 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.mjs +176 -9
- package/dist/tools/selection/index.cjs +9 -7
- package/dist/tools/selection/index.d.mts +4 -0
- package/dist/tools/selection/index.d.ts +4 -0
- package/dist/tools/selection/index.mjs +9 -7
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -21438,14 +21438,14 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
21438
21438
|
const alwaysInclude = clientTools.filter(isAlwaysIncluded);
|
|
21439
21439
|
const filterCandidates = clientTools.filter((t) => !isAlwaysIncluded(t));
|
|
21440
21440
|
if (filterCandidates.length === 0) {
|
|
21441
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
21441
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
21442
21442
|
}
|
|
21443
21443
|
if (!promptEmbeddings && noEmbeddingsReason === "error") {
|
|
21444
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
21444
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
21445
21445
|
}
|
|
21446
21446
|
if (!promptEmbeddings) {
|
|
21447
21447
|
if (activeToolSets.length === 0) {
|
|
21448
|
-
return { tools: [], activatedSetNames: /* @__PURE__ */ new Set() };
|
|
21448
|
+
return { tools: [], activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
21449
21449
|
}
|
|
21450
21450
|
const allSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
21451
21451
|
const activeSets = allSets.filter((s) => activeToolSets.includes(s.name));
|
|
@@ -21455,7 +21455,8 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
21455
21455
|
...alwaysInclude,
|
|
21456
21456
|
...filterCandidates.filter((t) => stickyMembers.has(getToolName2(t)))
|
|
21457
21457
|
],
|
|
21458
|
-
activatedSetNames: new Set(activeSets.map((s) => s.name))
|
|
21458
|
+
activatedSetNames: new Set(activeSets.map((s) => s.name)),
|
|
21459
|
+
matchedSetNames: /* @__PURE__ */ new Set()
|
|
21459
21460
|
};
|
|
21460
21461
|
}
|
|
21461
21462
|
const toolsNeedingEmbeddings = [];
|
|
@@ -21473,7 +21474,7 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
21473
21474
|
cache.set(toolsNeedingEmbeddings[i].name, embeddings[i]);
|
|
21474
21475
|
}
|
|
21475
21476
|
} catch {
|
|
21476
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
21477
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
21477
21478
|
}
|
|
21478
21479
|
}
|
|
21479
21480
|
const pseudoServerTools = [];
|
|
@@ -21519,16 +21520,171 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
21519
21520
|
activeSetNames
|
|
21520
21521
|
);
|
|
21521
21522
|
const activatedSetNames = activatedToolSetNames(scores, toolSets, activeSetNames);
|
|
21523
|
+
const matchedSetNames = activatedToolSetNames(scores, toolSets);
|
|
21522
21524
|
if (finalNames.size === 0) {
|
|
21523
|
-
return { tools: alwaysInclude, activatedSetNames };
|
|
21525
|
+
return { tools: alwaysInclude, activatedSetNames, matchedSetNames };
|
|
21524
21526
|
}
|
|
21525
21527
|
const filtered = filterCandidates.filter((t) => {
|
|
21526
21528
|
const name = getToolName2(t);
|
|
21527
21529
|
return name && finalNames.has(name);
|
|
21528
21530
|
});
|
|
21529
|
-
return { tools: [...alwaysInclude, ...filtered], activatedSetNames };
|
|
21531
|
+
return { tools: [...alwaysInclude, ...filtered], activatedSetNames, matchedSetNames };
|
|
21532
|
+
}
|
|
21533
|
+
|
|
21534
|
+
// src/lib/tools/toolCatalog.ts
|
|
21535
|
+
var TOOL_CATALOG = {
|
|
21536
|
+
// Gmail (src/tools/gmail.ts)
|
|
21537
|
+
gmail_search_messages: { label: "Search emails", provider: "gmail", connector: "Gmail" },
|
|
21538
|
+
gmail_get_message: { label: "Read an email", provider: "gmail", connector: "Gmail" },
|
|
21539
|
+
gmail_create_draft: { label: "Draft a reply", provider: "gmail", connector: "Gmail" },
|
|
21540
|
+
gmail_send_message: { label: "Send an email", provider: "gmail", connector: "Gmail" },
|
|
21541
|
+
// Google Calendar (src/tools/googleCalendar.ts)
|
|
21542
|
+
google_calendar_list_events: {
|
|
21543
|
+
label: "Search calendar events",
|
|
21544
|
+
provider: "gcalendar",
|
|
21545
|
+
connector: "Calendar"
|
|
21546
|
+
},
|
|
21547
|
+
google_calendar_create_event: {
|
|
21548
|
+
label: "Create calendar event",
|
|
21549
|
+
provider: "gcalendar",
|
|
21550
|
+
connector: "Calendar"
|
|
21551
|
+
},
|
|
21552
|
+
google_calendar_update_event: {
|
|
21553
|
+
label: "Update calendar event",
|
|
21554
|
+
provider: "gcalendar",
|
|
21555
|
+
connector: "Calendar"
|
|
21556
|
+
},
|
|
21557
|
+
// Google Drive (src/tools/googleDrive.ts)
|
|
21558
|
+
google_drive_search: { label: "Search files", provider: "gdrive", connector: "Drive" },
|
|
21559
|
+
google_drive_list_recent: { label: "List recent files", provider: "gdrive", connector: "Drive" },
|
|
21560
|
+
google_drive_get_content: { label: "Read file content", provider: "gdrive", connector: "Drive" },
|
|
21561
|
+
google_drive_create_file: {
|
|
21562
|
+
label: "Create a file in Drive",
|
|
21563
|
+
provider: "gdrive",
|
|
21564
|
+
connector: "Drive"
|
|
21565
|
+
},
|
|
21566
|
+
google_drive_update_file: {
|
|
21567
|
+
label: "Update a Drive file",
|
|
21568
|
+
provider: "gdrive",
|
|
21569
|
+
connector: "Drive"
|
|
21570
|
+
},
|
|
21571
|
+
// Notion (src/tools/notion.ts)
|
|
21572
|
+
"notion-search": { label: "Search", provider: "notion", connector: "Notion" },
|
|
21573
|
+
"notion-fetch": { label: "Read page", provider: "notion", connector: "Notion" },
|
|
21574
|
+
"notion-create-pages": { label: "Create page", provider: "notion", connector: "Notion" },
|
|
21575
|
+
"notion-update-page": { label: "Update page", provider: "notion", connector: "Notion" },
|
|
21576
|
+
"notion-move-pages": { label: "Move pages", provider: "notion", connector: "Notion" },
|
|
21577
|
+
"notion-duplicate-page": { label: "Duplicate page", provider: "notion", connector: "Notion" },
|
|
21578
|
+
"notion-create-database": { label: "Create database", provider: "notion", connector: "Notion" },
|
|
21579
|
+
"notion-update-data-source": {
|
|
21580
|
+
label: "Update data source",
|
|
21581
|
+
provider: "notion",
|
|
21582
|
+
connector: "Notion"
|
|
21583
|
+
},
|
|
21584
|
+
"notion-create-comment": { label: "Add a comment", provider: "notion", connector: "Notion" },
|
|
21585
|
+
"notion-get-comments": { label: "Read comments", provider: "notion", connector: "Notion" },
|
|
21586
|
+
"notion-get-users": {
|
|
21587
|
+
label: "List workspace members",
|
|
21588
|
+
provider: "notion",
|
|
21589
|
+
connector: "Notion"
|
|
21590
|
+
},
|
|
21591
|
+
"notion-get-teams": { label: "List teamspaces", provider: "notion", connector: "Notion" },
|
|
21592
|
+
// GitHub (src/tools/github.ts)
|
|
21593
|
+
github_api: { label: "Use GitHub", provider: "github", connector: "GitHub" },
|
|
21594
|
+
github_get_authenticated_user: {
|
|
21595
|
+
label: "Read GitHub profile",
|
|
21596
|
+
provider: "github",
|
|
21597
|
+
connector: "GitHub"
|
|
21598
|
+
},
|
|
21599
|
+
// X / Twitter (src/tools/x.ts)
|
|
21600
|
+
x_get_me: { label: "Get my X profile", provider: "x", connector: "X" },
|
|
21601
|
+
x_get_my_posts: { label: "Read my recent posts", provider: "x", connector: "X" },
|
|
21602
|
+
// Dropbox (src/tools/dropbox.ts)
|
|
21603
|
+
dropbox_list_folders: { label: "List files", provider: "dropbox", connector: "Dropbox" },
|
|
21604
|
+
dropbox_get_file_content: {
|
|
21605
|
+
label: "Read file content",
|
|
21606
|
+
provider: "dropbox",
|
|
21607
|
+
connector: "Dropbox"
|
|
21608
|
+
},
|
|
21609
|
+
dropbox_search: { label: "Search files", provider: "dropbox", connector: "Dropbox" },
|
|
21610
|
+
// Slack (src/tools/slack.ts)
|
|
21611
|
+
slack_get_me: { label: "Get my Slack profile", provider: "slack", connector: "Slack" },
|
|
21612
|
+
slack_list_channels: { label: "List channels", provider: "slack", connector: "Slack" },
|
|
21613
|
+
slack_list_dms: { label: "List direct messages", provider: "slack", connector: "Slack" },
|
|
21614
|
+
slack_search_messages: { label: "Search messages", provider: "slack", connector: "Slack" },
|
|
21615
|
+
slack_list_users: { label: "List members", provider: "slack", connector: "Slack" },
|
|
21616
|
+
slack_get_channel_history: {
|
|
21617
|
+
label: "Read channel history",
|
|
21618
|
+
provider: "slack",
|
|
21619
|
+
connector: "Slack"
|
|
21620
|
+
},
|
|
21621
|
+
slack_get_thread_replies: {
|
|
21622
|
+
label: "Read thread replies",
|
|
21623
|
+
provider: "slack",
|
|
21624
|
+
connector: "Slack"
|
|
21625
|
+
},
|
|
21626
|
+
slack_post_message: { label: "Post a message", provider: "slack", connector: "Slack" }
|
|
21627
|
+
};
|
|
21628
|
+
|
|
21629
|
+
// src/lib/tools/selection/activeToolSets.ts
|
|
21630
|
+
function mergeActiveToolSets(current, derived) {
|
|
21631
|
+
if (derived.length === 0) return current;
|
|
21632
|
+
const merged = Array.from(/* @__PURE__ */ new Set([...current, ...derived]));
|
|
21633
|
+
return merged.length === current.length ? current : merged;
|
|
21530
21634
|
}
|
|
21531
21635
|
|
|
21636
|
+
// src/lib/tools/selection/recentToolSets.ts
|
|
21637
|
+
var RECENT_TOOL_SET_TURNS = 2;
|
|
21638
|
+
var RECENT_TOOL_SET_CONVERSATION_LIMIT = 50;
|
|
21639
|
+
var CARRYABLE_TOOL_SETS = new Set(
|
|
21640
|
+
BUILT_IN_TOOL_SETS.filter(
|
|
21641
|
+
(s) => s.anchors.length > 0 && s.anchors.every((a) => a in TOOL_CATALOG)
|
|
21642
|
+
).map((s) => s.name)
|
|
21643
|
+
);
|
|
21644
|
+
var recentToolSets = /* @__PURE__ */ new WeakMap();
|
|
21645
|
+
function touch(conversations, conversationId) {
|
|
21646
|
+
const turns = conversations.get(conversationId);
|
|
21647
|
+
if (!turns) return void 0;
|
|
21648
|
+
conversations.delete(conversationId);
|
|
21649
|
+
conversations.set(conversationId, turns);
|
|
21650
|
+
return turns;
|
|
21651
|
+
}
|
|
21652
|
+
function carriedToolSets(database, conversationId) {
|
|
21653
|
+
if (!conversationId) return [];
|
|
21654
|
+
const conversations = recentToolSets.get(database);
|
|
21655
|
+
if (!conversations) return [];
|
|
21656
|
+
return [...touch(conversations, conversationId)?.keys() ?? []];
|
|
21657
|
+
}
|
|
21658
|
+
function recordToolSetTurn(database, conversationId, matched) {
|
|
21659
|
+
if (!conversationId) return;
|
|
21660
|
+
let conversations = recentToolSets.get(database);
|
|
21661
|
+
if (!conversations) {
|
|
21662
|
+
conversations = /* @__PURE__ */ new Map();
|
|
21663
|
+
recentToolSets.set(database, conversations);
|
|
21664
|
+
}
|
|
21665
|
+
const turns = touch(conversations, conversationId) ?? /* @__PURE__ */ new Map();
|
|
21666
|
+
for (const [name, left] of turns) {
|
|
21667
|
+
if (left > 1) turns.set(name, left - 1);
|
|
21668
|
+
else turns.delete(name);
|
|
21669
|
+
}
|
|
21670
|
+
for (const name of matched) {
|
|
21671
|
+
if (CARRYABLE_TOOL_SETS.has(name)) turns.set(name, RECENT_TOOL_SET_TURNS);
|
|
21672
|
+
}
|
|
21673
|
+
if (turns.size === 0) {
|
|
21674
|
+
conversations.delete(conversationId);
|
|
21675
|
+
return;
|
|
21676
|
+
}
|
|
21677
|
+
conversations.set(conversationId, turns);
|
|
21678
|
+
if (conversations.size > RECENT_TOOL_SET_CONVERSATION_LIMIT) {
|
|
21679
|
+
const oldest = conversations.keys().next().value;
|
|
21680
|
+
if (oldest !== void 0) conversations.delete(oldest);
|
|
21681
|
+
}
|
|
21682
|
+
}
|
|
21683
|
+
function resetRecentToolSets() {
|
|
21684
|
+
recentToolSets = /* @__PURE__ */ new WeakMap();
|
|
21685
|
+
}
|
|
21686
|
+
onClearAllEncryptionState(resetRecentToolSets);
|
|
21687
|
+
|
|
21532
21688
|
// src/expo/useChatStorage.ts
|
|
21533
21689
|
var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
21534
21690
|
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
@@ -22408,6 +22564,7 @@ function useChatStorage(options) {
|
|
|
22408
22564
|
}
|
|
22409
22565
|
let narrowedClientTools2 = clientTools;
|
|
22410
22566
|
let clientActivatedSetNames2;
|
|
22567
|
+
let matchedToolSets2 = /* @__PURE__ */ new Set();
|
|
22411
22568
|
if (clientTools?.length) {
|
|
22412
22569
|
try {
|
|
22413
22570
|
if (!skipUserEmbedding && getTokenRef.current && messageContent.length >= MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
@@ -22428,17 +22585,25 @@ function useChatStorage(options) {
|
|
|
22428
22585
|
narrowedClientTools2 = clientTools.filter((t) => keep.has(getToolName2(t)));
|
|
22429
22586
|
}
|
|
22430
22587
|
} else if (getTokenRef.current) {
|
|
22431
|
-
const {
|
|
22588
|
+
const {
|
|
22589
|
+
tools: autoTools,
|
|
22590
|
+
activatedSetNames,
|
|
22591
|
+
matchedSetNames
|
|
22592
|
+
} = await autoFilterClientTools(
|
|
22432
22593
|
clientTools,
|
|
22433
22594
|
skipUserEmbedding ?? null,
|
|
22434
22595
|
clientToolFilterCache,
|
|
22435
22596
|
{ getToken: getTokenRef.current, baseUrl, model: embeddingModel },
|
|
22436
22597
|
extraToolSets ?? [],
|
|
22437
|
-
|
|
22598
|
+
mergeActiveToolSets(
|
|
22599
|
+
activeToolSetsRef.current ?? [],
|
|
22600
|
+
carriedToolSets(database, currentConversationId)
|
|
22601
|
+
),
|
|
22438
22602
|
skipEmbeddingFailed ? "error" : "short-prompt"
|
|
22439
22603
|
);
|
|
22440
22604
|
narrowedClientTools2 = autoTools;
|
|
22441
22605
|
clientActivatedSetNames2 = activatedSetNames;
|
|
22606
|
+
matchedToolSets2 = matchedSetNames;
|
|
22442
22607
|
}
|
|
22443
22608
|
} catch (error) {
|
|
22444
22609
|
getLogger().warn("[useChatStorage] client tool filtering failed (skipStorage):", error);
|
|
@@ -22490,6 +22655,7 @@ function useChatStorage(options) {
|
|
|
22490
22655
|
headers
|
|
22491
22656
|
});
|
|
22492
22657
|
if ("detached" in result2 && result2.detached) {
|
|
22658
|
+
recordToolSetTurn(database, currentConversationId, matchedToolSets2);
|
|
22493
22659
|
return {
|
|
22494
22660
|
data: result2.data,
|
|
22495
22661
|
error: result2.error,
|
|
@@ -22503,6 +22669,7 @@ function useChatStorage(options) {
|
|
|
22503
22669
|
error: result2.error || "Unknown error"
|
|
22504
22670
|
};
|
|
22505
22671
|
}
|
|
22672
|
+
recordToolSetTurn(database, currentConversationId, matchedToolSets2);
|
|
22506
22673
|
const skipRefreshGetToken = getTokenRef.current;
|
|
22507
22674
|
const skipRefreshData = result2.data;
|
|
22508
22675
|
if (skipRefreshGetToken) {
|
|
@@ -22718,6 +22885,7 @@ function useChatStorage(options) {
|
|
|
22718
22885
|
}
|
|
22719
22886
|
let narrowedClientTools = clientTools;
|
|
22720
22887
|
let clientActivatedSetNames;
|
|
22888
|
+
let matchedToolSets = /* @__PURE__ */ new Set();
|
|
22721
22889
|
if (clientTools?.length) {
|
|
22722
22890
|
try {
|
|
22723
22891
|
if (!userMessageEmbedding && getTokenRef.current && contentForStorage.length >= MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
@@ -22734,17 +22902,25 @@ function useChatStorage(options) {
|
|
|
22734
22902
|
narrowedClientTools = clientTools.filter((t) => keep.has(getToolName2(t)));
|
|
22735
22903
|
}
|
|
22736
22904
|
} else if (getTokenRef.current) {
|
|
22737
|
-
const {
|
|
22905
|
+
const {
|
|
22906
|
+
tools: autoTools,
|
|
22907
|
+
activatedSetNames,
|
|
22908
|
+
matchedSetNames
|
|
22909
|
+
} = await autoFilterClientTools(
|
|
22738
22910
|
clientTools,
|
|
22739
22911
|
userMessageEmbedding ?? null,
|
|
22740
22912
|
clientToolFilterCache,
|
|
22741
22913
|
{ getToken: getTokenRef.current, baseUrl, model: embeddingModel },
|
|
22742
22914
|
extraToolSets ?? [],
|
|
22743
|
-
|
|
22915
|
+
mergeActiveToolSets(
|
|
22916
|
+
activeToolSetsRef.current ?? [],
|
|
22917
|
+
carriedToolSets(database, convId)
|
|
22918
|
+
),
|
|
22744
22919
|
userMessageEmbeddingFailed ? "error" : "short-prompt"
|
|
22745
22920
|
);
|
|
22746
22921
|
narrowedClientTools = autoTools;
|
|
22747
22922
|
clientActivatedSetNames = activatedSetNames;
|
|
22923
|
+
matchedToolSets = matchedSetNames;
|
|
22748
22924
|
}
|
|
22749
22925
|
mergedTools = filteredServerTools.length > 0 || (narrowedClientTools?.length ?? 0) > 0 ? mergeTools(
|
|
22750
22926
|
filteredServerTools,
|
|
@@ -22831,6 +23007,7 @@ function useChatStorage(options) {
|
|
|
22831
23007
|
const responseDuration = (Date.now() - startTime) / 1e3;
|
|
22832
23008
|
const detachedResult = result;
|
|
22833
23009
|
if (detachedResult.detached) {
|
|
23010
|
+
recordToolSetTurn(database, convId, matchedToolSets);
|
|
22834
23011
|
const rowId = effectiveAssistantUniqueId ?? `msg_${(0, import_uuid5.v7)()}`;
|
|
22835
23012
|
pendingResumeRef.current = {
|
|
22836
23013
|
handle: detachedResult.resume ?? null,
|
|
@@ -22899,6 +23076,7 @@ function useChatStorage(options) {
|
|
|
22899
23076
|
],
|
|
22900
23077
|
usage: void 0
|
|
22901
23078
|
};
|
|
23079
|
+
recordToolSetTurn(database, convId, matchedToolSets);
|
|
22902
23080
|
return {
|
|
22903
23081
|
data: responseData2,
|
|
22904
23082
|
error: null,
|
|
@@ -22937,6 +23115,7 @@ function useChatStorage(options) {
|
|
|
22937
23115
|
userMessage: { ...storedUserMessage, error: errorMessage }
|
|
22938
23116
|
};
|
|
22939
23117
|
}
|
|
23118
|
+
recordToolSetTurn(database, convId, matchedToolSets);
|
|
22940
23119
|
const responseData = result.data;
|
|
22941
23120
|
let assistantContent = "";
|
|
22942
23121
|
let thinkingContent;
|
package/dist/expo/index.mjs
CHANGED
|
@@ -19722,14 +19722,14 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
19722
19722
|
const alwaysInclude = clientTools.filter(isAlwaysIncluded);
|
|
19723
19723
|
const filterCandidates = clientTools.filter((t) => !isAlwaysIncluded(t));
|
|
19724
19724
|
if (filterCandidates.length === 0) {
|
|
19725
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
19725
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
19726
19726
|
}
|
|
19727
19727
|
if (!promptEmbeddings && noEmbeddingsReason === "error") {
|
|
19728
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
19728
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
19729
19729
|
}
|
|
19730
19730
|
if (!promptEmbeddings) {
|
|
19731
19731
|
if (activeToolSets.length === 0) {
|
|
19732
|
-
return { tools: [], activatedSetNames: /* @__PURE__ */ new Set() };
|
|
19732
|
+
return { tools: [], activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
19733
19733
|
}
|
|
19734
19734
|
const allSets = extraToolSets.length > 0 ? [...BUILT_IN_TOOL_SETS, ...extraToolSets] : BUILT_IN_TOOL_SETS;
|
|
19735
19735
|
const activeSets = allSets.filter((s) => activeToolSets.includes(s.name));
|
|
@@ -19739,7 +19739,8 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
19739
19739
|
...alwaysInclude,
|
|
19740
19740
|
...filterCandidates.filter((t) => stickyMembers.has(getToolName2(t)))
|
|
19741
19741
|
],
|
|
19742
|
-
activatedSetNames: new Set(activeSets.map((s) => s.name))
|
|
19742
|
+
activatedSetNames: new Set(activeSets.map((s) => s.name)),
|
|
19743
|
+
matchedSetNames: /* @__PURE__ */ new Set()
|
|
19743
19744
|
};
|
|
19744
19745
|
}
|
|
19745
19746
|
const toolsNeedingEmbeddings = [];
|
|
@@ -19757,7 +19758,7 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
19757
19758
|
cache.set(toolsNeedingEmbeddings[i].name, embeddings[i]);
|
|
19758
19759
|
}
|
|
19759
19760
|
} catch {
|
|
19760
|
-
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set() };
|
|
19761
|
+
return { tools: clientTools, activatedSetNames: /* @__PURE__ */ new Set(), matchedSetNames: /* @__PURE__ */ new Set() };
|
|
19761
19762
|
}
|
|
19762
19763
|
}
|
|
19763
19764
|
const pseudoServerTools = [];
|
|
@@ -19803,16 +19804,171 @@ async function autoFilterClientTools(clientTools, promptEmbeddings, cache, embed
|
|
|
19803
19804
|
activeSetNames
|
|
19804
19805
|
);
|
|
19805
19806
|
const activatedSetNames = activatedToolSetNames(scores, toolSets, activeSetNames);
|
|
19807
|
+
const matchedSetNames = activatedToolSetNames(scores, toolSets);
|
|
19806
19808
|
if (finalNames.size === 0) {
|
|
19807
|
-
return { tools: alwaysInclude, activatedSetNames };
|
|
19809
|
+
return { tools: alwaysInclude, activatedSetNames, matchedSetNames };
|
|
19808
19810
|
}
|
|
19809
19811
|
const filtered = filterCandidates.filter((t) => {
|
|
19810
19812
|
const name = getToolName2(t);
|
|
19811
19813
|
return name && finalNames.has(name);
|
|
19812
19814
|
});
|
|
19813
|
-
return { tools: [...alwaysInclude, ...filtered], activatedSetNames };
|
|
19815
|
+
return { tools: [...alwaysInclude, ...filtered], activatedSetNames, matchedSetNames };
|
|
19814
19816
|
}
|
|
19815
19817
|
|
|
19818
|
+
// src/lib/tools/toolCatalog.ts
|
|
19819
|
+
var TOOL_CATALOG = {
|
|
19820
|
+
// Gmail (src/tools/gmail.ts)
|
|
19821
|
+
gmail_search_messages: { label: "Search emails", provider: "gmail", connector: "Gmail" },
|
|
19822
|
+
gmail_get_message: { label: "Read an email", provider: "gmail", connector: "Gmail" },
|
|
19823
|
+
gmail_create_draft: { label: "Draft a reply", provider: "gmail", connector: "Gmail" },
|
|
19824
|
+
gmail_send_message: { label: "Send an email", provider: "gmail", connector: "Gmail" },
|
|
19825
|
+
// Google Calendar (src/tools/googleCalendar.ts)
|
|
19826
|
+
google_calendar_list_events: {
|
|
19827
|
+
label: "Search calendar events",
|
|
19828
|
+
provider: "gcalendar",
|
|
19829
|
+
connector: "Calendar"
|
|
19830
|
+
},
|
|
19831
|
+
google_calendar_create_event: {
|
|
19832
|
+
label: "Create calendar event",
|
|
19833
|
+
provider: "gcalendar",
|
|
19834
|
+
connector: "Calendar"
|
|
19835
|
+
},
|
|
19836
|
+
google_calendar_update_event: {
|
|
19837
|
+
label: "Update calendar event",
|
|
19838
|
+
provider: "gcalendar",
|
|
19839
|
+
connector: "Calendar"
|
|
19840
|
+
},
|
|
19841
|
+
// Google Drive (src/tools/googleDrive.ts)
|
|
19842
|
+
google_drive_search: { label: "Search files", provider: "gdrive", connector: "Drive" },
|
|
19843
|
+
google_drive_list_recent: { label: "List recent files", provider: "gdrive", connector: "Drive" },
|
|
19844
|
+
google_drive_get_content: { label: "Read file content", provider: "gdrive", connector: "Drive" },
|
|
19845
|
+
google_drive_create_file: {
|
|
19846
|
+
label: "Create a file in Drive",
|
|
19847
|
+
provider: "gdrive",
|
|
19848
|
+
connector: "Drive"
|
|
19849
|
+
},
|
|
19850
|
+
google_drive_update_file: {
|
|
19851
|
+
label: "Update a Drive file",
|
|
19852
|
+
provider: "gdrive",
|
|
19853
|
+
connector: "Drive"
|
|
19854
|
+
},
|
|
19855
|
+
// Notion (src/tools/notion.ts)
|
|
19856
|
+
"notion-search": { label: "Search", provider: "notion", connector: "Notion" },
|
|
19857
|
+
"notion-fetch": { label: "Read page", provider: "notion", connector: "Notion" },
|
|
19858
|
+
"notion-create-pages": { label: "Create page", provider: "notion", connector: "Notion" },
|
|
19859
|
+
"notion-update-page": { label: "Update page", provider: "notion", connector: "Notion" },
|
|
19860
|
+
"notion-move-pages": { label: "Move pages", provider: "notion", connector: "Notion" },
|
|
19861
|
+
"notion-duplicate-page": { label: "Duplicate page", provider: "notion", connector: "Notion" },
|
|
19862
|
+
"notion-create-database": { label: "Create database", provider: "notion", connector: "Notion" },
|
|
19863
|
+
"notion-update-data-source": {
|
|
19864
|
+
label: "Update data source",
|
|
19865
|
+
provider: "notion",
|
|
19866
|
+
connector: "Notion"
|
|
19867
|
+
},
|
|
19868
|
+
"notion-create-comment": { label: "Add a comment", provider: "notion", connector: "Notion" },
|
|
19869
|
+
"notion-get-comments": { label: "Read comments", provider: "notion", connector: "Notion" },
|
|
19870
|
+
"notion-get-users": {
|
|
19871
|
+
label: "List workspace members",
|
|
19872
|
+
provider: "notion",
|
|
19873
|
+
connector: "Notion"
|
|
19874
|
+
},
|
|
19875
|
+
"notion-get-teams": { label: "List teamspaces", provider: "notion", connector: "Notion" },
|
|
19876
|
+
// GitHub (src/tools/github.ts)
|
|
19877
|
+
github_api: { label: "Use GitHub", provider: "github", connector: "GitHub" },
|
|
19878
|
+
github_get_authenticated_user: {
|
|
19879
|
+
label: "Read GitHub profile",
|
|
19880
|
+
provider: "github",
|
|
19881
|
+
connector: "GitHub"
|
|
19882
|
+
},
|
|
19883
|
+
// X / Twitter (src/tools/x.ts)
|
|
19884
|
+
x_get_me: { label: "Get my X profile", provider: "x", connector: "X" },
|
|
19885
|
+
x_get_my_posts: { label: "Read my recent posts", provider: "x", connector: "X" },
|
|
19886
|
+
// Dropbox (src/tools/dropbox.ts)
|
|
19887
|
+
dropbox_list_folders: { label: "List files", provider: "dropbox", connector: "Dropbox" },
|
|
19888
|
+
dropbox_get_file_content: {
|
|
19889
|
+
label: "Read file content",
|
|
19890
|
+
provider: "dropbox",
|
|
19891
|
+
connector: "Dropbox"
|
|
19892
|
+
},
|
|
19893
|
+
dropbox_search: { label: "Search files", provider: "dropbox", connector: "Dropbox" },
|
|
19894
|
+
// Slack (src/tools/slack.ts)
|
|
19895
|
+
slack_get_me: { label: "Get my Slack profile", provider: "slack", connector: "Slack" },
|
|
19896
|
+
slack_list_channels: { label: "List channels", provider: "slack", connector: "Slack" },
|
|
19897
|
+
slack_list_dms: { label: "List direct messages", provider: "slack", connector: "Slack" },
|
|
19898
|
+
slack_search_messages: { label: "Search messages", provider: "slack", connector: "Slack" },
|
|
19899
|
+
slack_list_users: { label: "List members", provider: "slack", connector: "Slack" },
|
|
19900
|
+
slack_get_channel_history: {
|
|
19901
|
+
label: "Read channel history",
|
|
19902
|
+
provider: "slack",
|
|
19903
|
+
connector: "Slack"
|
|
19904
|
+
},
|
|
19905
|
+
slack_get_thread_replies: {
|
|
19906
|
+
label: "Read thread replies",
|
|
19907
|
+
provider: "slack",
|
|
19908
|
+
connector: "Slack"
|
|
19909
|
+
},
|
|
19910
|
+
slack_post_message: { label: "Post a message", provider: "slack", connector: "Slack" }
|
|
19911
|
+
};
|
|
19912
|
+
|
|
19913
|
+
// src/lib/tools/selection/activeToolSets.ts
|
|
19914
|
+
function mergeActiveToolSets(current, derived) {
|
|
19915
|
+
if (derived.length === 0) return current;
|
|
19916
|
+
const merged = Array.from(/* @__PURE__ */ new Set([...current, ...derived]));
|
|
19917
|
+
return merged.length === current.length ? current : merged;
|
|
19918
|
+
}
|
|
19919
|
+
|
|
19920
|
+
// src/lib/tools/selection/recentToolSets.ts
|
|
19921
|
+
var RECENT_TOOL_SET_TURNS = 2;
|
|
19922
|
+
var RECENT_TOOL_SET_CONVERSATION_LIMIT = 50;
|
|
19923
|
+
var CARRYABLE_TOOL_SETS = new Set(
|
|
19924
|
+
BUILT_IN_TOOL_SETS.filter(
|
|
19925
|
+
(s) => s.anchors.length > 0 && s.anchors.every((a) => a in TOOL_CATALOG)
|
|
19926
|
+
).map((s) => s.name)
|
|
19927
|
+
);
|
|
19928
|
+
var recentToolSets = /* @__PURE__ */ new WeakMap();
|
|
19929
|
+
function touch(conversations, conversationId) {
|
|
19930
|
+
const turns = conversations.get(conversationId);
|
|
19931
|
+
if (!turns) return void 0;
|
|
19932
|
+
conversations.delete(conversationId);
|
|
19933
|
+
conversations.set(conversationId, turns);
|
|
19934
|
+
return turns;
|
|
19935
|
+
}
|
|
19936
|
+
function carriedToolSets(database, conversationId) {
|
|
19937
|
+
if (!conversationId) return [];
|
|
19938
|
+
const conversations = recentToolSets.get(database);
|
|
19939
|
+
if (!conversations) return [];
|
|
19940
|
+
return [...touch(conversations, conversationId)?.keys() ?? []];
|
|
19941
|
+
}
|
|
19942
|
+
function recordToolSetTurn(database, conversationId, matched) {
|
|
19943
|
+
if (!conversationId) return;
|
|
19944
|
+
let conversations = recentToolSets.get(database);
|
|
19945
|
+
if (!conversations) {
|
|
19946
|
+
conversations = /* @__PURE__ */ new Map();
|
|
19947
|
+
recentToolSets.set(database, conversations);
|
|
19948
|
+
}
|
|
19949
|
+
const turns = touch(conversations, conversationId) ?? /* @__PURE__ */ new Map();
|
|
19950
|
+
for (const [name, left] of turns) {
|
|
19951
|
+
if (left > 1) turns.set(name, left - 1);
|
|
19952
|
+
else turns.delete(name);
|
|
19953
|
+
}
|
|
19954
|
+
for (const name of matched) {
|
|
19955
|
+
if (CARRYABLE_TOOL_SETS.has(name)) turns.set(name, RECENT_TOOL_SET_TURNS);
|
|
19956
|
+
}
|
|
19957
|
+
if (turns.size === 0) {
|
|
19958
|
+
conversations.delete(conversationId);
|
|
19959
|
+
return;
|
|
19960
|
+
}
|
|
19961
|
+
conversations.set(conversationId, turns);
|
|
19962
|
+
if (conversations.size > RECENT_TOOL_SET_CONVERSATION_LIMIT) {
|
|
19963
|
+
const oldest = conversations.keys().next().value;
|
|
19964
|
+
if (oldest !== void 0) conversations.delete(oldest);
|
|
19965
|
+
}
|
|
19966
|
+
}
|
|
19967
|
+
function resetRecentToolSets() {
|
|
19968
|
+
recentToolSets = /* @__PURE__ */ new WeakMap();
|
|
19969
|
+
}
|
|
19970
|
+
onClearAllEncryptionState(resetRecentToolSets);
|
|
19971
|
+
|
|
19816
19972
|
// src/expo/useChatStorage.ts
|
|
19817
19973
|
var CONVERSATION_REDACTOR_LIMIT = 50;
|
|
19818
19974
|
var NO_CONVERSATION_KEY = "__no_conversation__";
|
|
@@ -20692,6 +20848,7 @@ function useChatStorage(options) {
|
|
|
20692
20848
|
}
|
|
20693
20849
|
let narrowedClientTools2 = clientTools;
|
|
20694
20850
|
let clientActivatedSetNames2;
|
|
20851
|
+
let matchedToolSets2 = /* @__PURE__ */ new Set();
|
|
20695
20852
|
if (clientTools?.length) {
|
|
20696
20853
|
try {
|
|
20697
20854
|
if (!skipUserEmbedding && getTokenRef.current && messageContent.length >= MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
@@ -20712,17 +20869,25 @@ function useChatStorage(options) {
|
|
|
20712
20869
|
narrowedClientTools2 = clientTools.filter((t) => keep.has(getToolName2(t)));
|
|
20713
20870
|
}
|
|
20714
20871
|
} else if (getTokenRef.current) {
|
|
20715
|
-
const {
|
|
20872
|
+
const {
|
|
20873
|
+
tools: autoTools,
|
|
20874
|
+
activatedSetNames,
|
|
20875
|
+
matchedSetNames
|
|
20876
|
+
} = await autoFilterClientTools(
|
|
20716
20877
|
clientTools,
|
|
20717
20878
|
skipUserEmbedding ?? null,
|
|
20718
20879
|
clientToolFilterCache,
|
|
20719
20880
|
{ getToken: getTokenRef.current, baseUrl, model: embeddingModel },
|
|
20720
20881
|
extraToolSets ?? [],
|
|
20721
|
-
|
|
20882
|
+
mergeActiveToolSets(
|
|
20883
|
+
activeToolSetsRef.current ?? [],
|
|
20884
|
+
carriedToolSets(database, currentConversationId)
|
|
20885
|
+
),
|
|
20722
20886
|
skipEmbeddingFailed ? "error" : "short-prompt"
|
|
20723
20887
|
);
|
|
20724
20888
|
narrowedClientTools2 = autoTools;
|
|
20725
20889
|
clientActivatedSetNames2 = activatedSetNames;
|
|
20890
|
+
matchedToolSets2 = matchedSetNames;
|
|
20726
20891
|
}
|
|
20727
20892
|
} catch (error) {
|
|
20728
20893
|
getLogger().warn("[useChatStorage] client tool filtering failed (skipStorage):", error);
|
|
@@ -20774,6 +20939,7 @@ function useChatStorage(options) {
|
|
|
20774
20939
|
headers
|
|
20775
20940
|
});
|
|
20776
20941
|
if ("detached" in result2 && result2.detached) {
|
|
20942
|
+
recordToolSetTurn(database, currentConversationId, matchedToolSets2);
|
|
20777
20943
|
return {
|
|
20778
20944
|
data: result2.data,
|
|
20779
20945
|
error: result2.error,
|
|
@@ -20787,6 +20953,7 @@ function useChatStorage(options) {
|
|
|
20787
20953
|
error: result2.error || "Unknown error"
|
|
20788
20954
|
};
|
|
20789
20955
|
}
|
|
20956
|
+
recordToolSetTurn(database, currentConversationId, matchedToolSets2);
|
|
20790
20957
|
const skipRefreshGetToken = getTokenRef.current;
|
|
20791
20958
|
const skipRefreshData = result2.data;
|
|
20792
20959
|
if (skipRefreshGetToken) {
|
|
@@ -21002,6 +21169,7 @@ function useChatStorage(options) {
|
|
|
21002
21169
|
}
|
|
21003
21170
|
let narrowedClientTools = clientTools;
|
|
21004
21171
|
let clientActivatedSetNames;
|
|
21172
|
+
let matchedToolSets = /* @__PURE__ */ new Set();
|
|
21005
21173
|
if (clientTools?.length) {
|
|
21006
21174
|
try {
|
|
21007
21175
|
if (!userMessageEmbedding && getTokenRef.current && contentForStorage.length >= MIN_CONTENT_LENGTH_FOR_TOOLS) {
|
|
@@ -21018,17 +21186,25 @@ function useChatStorage(options) {
|
|
|
21018
21186
|
narrowedClientTools = clientTools.filter((t) => keep.has(getToolName2(t)));
|
|
21019
21187
|
}
|
|
21020
21188
|
} else if (getTokenRef.current) {
|
|
21021
|
-
const {
|
|
21189
|
+
const {
|
|
21190
|
+
tools: autoTools,
|
|
21191
|
+
activatedSetNames,
|
|
21192
|
+
matchedSetNames
|
|
21193
|
+
} = await autoFilterClientTools(
|
|
21022
21194
|
clientTools,
|
|
21023
21195
|
userMessageEmbedding ?? null,
|
|
21024
21196
|
clientToolFilterCache,
|
|
21025
21197
|
{ getToken: getTokenRef.current, baseUrl, model: embeddingModel },
|
|
21026
21198
|
extraToolSets ?? [],
|
|
21027
|
-
|
|
21199
|
+
mergeActiveToolSets(
|
|
21200
|
+
activeToolSetsRef.current ?? [],
|
|
21201
|
+
carriedToolSets(database, convId)
|
|
21202
|
+
),
|
|
21028
21203
|
userMessageEmbeddingFailed ? "error" : "short-prompt"
|
|
21029
21204
|
);
|
|
21030
21205
|
narrowedClientTools = autoTools;
|
|
21031
21206
|
clientActivatedSetNames = activatedSetNames;
|
|
21207
|
+
matchedToolSets = matchedSetNames;
|
|
21032
21208
|
}
|
|
21033
21209
|
mergedTools = filteredServerTools.length > 0 || (narrowedClientTools?.length ?? 0) > 0 ? mergeTools(
|
|
21034
21210
|
filteredServerTools,
|
|
@@ -21115,6 +21291,7 @@ function useChatStorage(options) {
|
|
|
21115
21291
|
const responseDuration = (Date.now() - startTime) / 1e3;
|
|
21116
21292
|
const detachedResult = result;
|
|
21117
21293
|
if (detachedResult.detached) {
|
|
21294
|
+
recordToolSetTurn(database, convId, matchedToolSets);
|
|
21118
21295
|
const rowId = effectiveAssistantUniqueId ?? `msg_${uuidv75()}`;
|
|
21119
21296
|
pendingResumeRef.current = {
|
|
21120
21297
|
handle: detachedResult.resume ?? null,
|
|
@@ -21183,6 +21360,7 @@ function useChatStorage(options) {
|
|
|
21183
21360
|
],
|
|
21184
21361
|
usage: void 0
|
|
21185
21362
|
};
|
|
21363
|
+
recordToolSetTurn(database, convId, matchedToolSets);
|
|
21186
21364
|
return {
|
|
21187
21365
|
data: responseData2,
|
|
21188
21366
|
error: null,
|
|
@@ -21221,6 +21399,7 @@ function useChatStorage(options) {
|
|
|
21221
21399
|
userMessage: { ...storedUserMessage, error: errorMessage }
|
|
21222
21400
|
};
|
|
21223
21401
|
}
|
|
21402
|
+
recordToolSetTurn(database, convId, matchedToolSets);
|
|
21224
21403
|
const responseData = result.data;
|
|
21225
21404
|
let assistantContent = "";
|
|
21226
21405
|
let thinkingContent;
|