Skip to content

Commit 268f092

Browse files
committed
Implement the PR suggestions from Cubic
1 parent f09c3c5 commit 268f092

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/semantic-search.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,17 @@ export class SemanticSearchClient {
148148
payload.connector = options.connector;
149149
}
150150

151-
try {
152-
const controller = new AbortController();
153-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
151+
const controller = new AbortController();
152+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
154153

154+
try {
155155
const response = await fetch(url, {
156156
method: 'POST',
157157
headers,
158158
body: JSON.stringify(payload),
159159
signal: controller.signal,
160160
});
161161

162-
clearTimeout(timeoutId);
163-
164162
if (!response.ok) {
165163
const text = await response.text();
166164
throw new SemanticSearchError(`API error: ${response.status} - ${text}`);
@@ -179,6 +177,8 @@ export class SemanticSearchClient {
179177
`Request failed: ${error instanceof Error ? error.message : String(error)}`,
180178
{ cause: error },
181179
);
180+
} finally {
181+
clearTimeout(timeoutId);
182182
}
183183
}
184184

src/tool.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ export class Tools implements Iterable<BaseTool> {
504504
getConnectors(): Set<string> {
505505
const connectors = new Set<string>();
506506
for (const tool of this.tools) {
507+
// Skip internal/utility tools (e.g. tool_search, tool_execute, tool_feedback)
508+
if (tool.name.startsWith('tool_')) continue;
507509
const connector = tool.name.split('_')[0]?.toLowerCase();
508510
if (connector) {
509511
connectors.add(connector);
@@ -942,6 +944,8 @@ function semanticToolSearch(semanticClient: SemanticSearchClient): BaseTool {
942944
});
943945

944946
const seen = new Set<string>();
947+
// Result shape intentionally omits `parameters` (unlike local tool_search) to match
948+
// the Python SDK's create_semantic_tool_search. The semantic API doesn't return schemas.
945949
const toolsData: Array<Record<string, unknown>> = [];
946950
for (const r of response.results) {
947951
if (r.similarityScore >= minScore) {

src/toolsets.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { type RpcActionResponse, RpcClient } from './rpc-client';
88
import {
99
SemanticSearchClient,
1010
SemanticSearchError,
11+
type SemanticSearchResponse,
1112
type SemanticSearchResult,
1213
normalizeActionName,
1314
} from './semantic-search';
@@ -341,7 +342,7 @@ export class StackOneToolSet {
341342
const fallbackToLocal = options?.fallbackToLocal ?? true;
342343
const accountIds = options?.accountIds;
343344

344-
let allTools: Tools;
345+
let allTools: Tools | undefined;
345346
try {
346347
// Step 1: Fetch all tools to get available connectors from linked accounts
347348
allTools = await this.fetchTools({ accountIds });
@@ -352,6 +353,8 @@ export class StackOneToolSet {
352353
}
353354

354355
// Step 2: Query semantic search API
356+
// topK is intentionally omitted here (matching Python SDK) to let the backend
357+
// return its default set; client-side filtering + per-connector fallback handle sizing.
355358
const response = await this.semanticClient.search(query, { connector });
356359

357360
// Step 3: Filter results to only available connectors and min_score
@@ -432,7 +435,7 @@ export class StackOneToolSet {
432435
// Note: The Python SDK logs a warning here via logger.warning(). A similar
433436
// logging mechanism can be added when a logging strategy is established.
434437
// allTools may not be defined if fetchTools failed before semantic search
435-
if (!allTools!) {
438+
if (!allTools) {
436439
throw error;
437440
}
438441

@@ -498,7 +501,7 @@ export class StackOneToolSet {
498501
}
499502
}
500503

501-
let response;
504+
let response: SemanticSearchResponse;
502505
try {
503506
response = await this.semanticClient.search(query, {
504507
connector,

0 commit comments

Comments
 (0)