8
import { resolveToolRouterSession } from 'src/effects/create-tool-router-session';
9
import { buildMinimalPayloadFromSchema } from 'src/ui/build-minimal-payload';
10
import { ComposioClientSingleton } from 'src/services/composio-clients';
11
-import { idempotent } from 'src/services/composio-request';
11
+import { decode, idempotent } from 'src/services/composio-request';
12
+import { SearchToolSchemas, ToolSearchResponse } from 'src/models/tool-search';
13
import { isRemoteCustomToolSlug } from 'src/utils/remote-custom-toolkit';
14
import { toolInputRequiredError } from 'src/utils/tool-input-required';
15
import {
29
stripSearchResultMetadata,
30
toHomeRelativePath,
31
TOOL_SCHEMA_PATH_FORMAT,
31
- type SearchResponseRecord,
32
- type SearchToolSchema,
32
} from './tools.search.format';
33
34
export type ToolsSearchParams = {
42
const invalidSearchInput = commandInputError('search');
43
44
const buildSearchJsonPayload = (params: {
46
- searchResponse: SearchResponseRecord;
45
+ searchResponse: ToolSearchResponse;
46
cacheScope: { orgId?: string; consumerUserId?: string };
47
projectScope: { orgId: string; projectId: string };
48
nextSteps: Array<{ action: string; command: string }>;
150
const searchPayload = {
151
queries: queries.map(query => ({ use_case: query })),
152
};
154
- // The command reads a few of the search response's fields; the rest, enums
153
+ // Decoded with the CLI's schema for the fields it reads; the rest, enums
154
// among them, may change without this version of the CLI noticing.
155
const searchResponse = yield* client.toolRouter.session
156
.search(sessionId, searchPayload, idempotent)
158
- .pipe(failedWith(ToolsSearchRequestError, 'Failed to search tools.'));
157
+ .pipe(
158
+ Effect.flatMap(decode(ToolSearchResponse, { operation: 'toolRouter.session.search' })),
159
+ failedWith(ToolsSearchRequestError, 'Failed to search tools.')
160
+ );
161
const customToolSlugsMissingSchemas = Object.entries(searchResponse.tool_schemas)
162
.filter(([slug, schema]) => isRemoteCustomToolSlug(slug) && !schema.input_schema)
163
.map(([slug]) => slug);
193
return yield* schemasFailed(new Error(schemaResponse.error));
194
}
195
194
- const resolvedSchemas = schemaResponse.data.tool_schemas;
195
- if (!resolvedSchemas || typeof resolvedSchemas !== 'object') {
196
- return yield* schemasFailed(new Error('Tool Router returned no tool schemas.'));
197
- }
196
+ const resolvedSchemas = yield* decode(SearchToolSchemas, {
197
+ operation: 'toolRouter.session.executeMeta',
198
+ })(schemaResponse.data.tool_schemas).pipe(Effect.mapError(schemasFailed));
199
200
return {
201
...searchResponse,
201
- tool_schemas: {
202
- ...searchResponse.tool_schemas,
203
- ...(resolvedSchemas as Record<string, SearchToolSchema>),
204
- },
202
+ tool_schemas: { ...searchResponse.tool_schemas, ...resolvedSchemas },
203
};
204
});
205
return {
294
limit: clampedLimit,
295
resultCount: totalToolCount,
296
toolRouterSessionId: searchResult.historyScope?.toolRouterSessionId,
299
- nextSteps: searchResponse.next_steps_guidance,
297
+ nextSteps: searchResponse.next_steps_guidance ?? [],
298
},
299
}).pipe(Effect.catch(() => Effect.void));
300
303
ui,
304
queries,
305
resultsWithTools,
308
- nextStepsGuidance: searchResponse.next_steps_guidance,
306
+ nextStepsGuidance: searchResponse.next_steps_guidance ?? [],
307
firstSlug,
308
firstDataArg,
309
tree,
312
- error: searchResponse.error,
310
+ error: searchResponse.error ?? null,
311
});
312
} else if (emitJson) {
313
const outputJson = JSON.stringify(outputForJq, null, 2);