aui-agent-builder 0.4.6 → 0.4.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.
Files changed (53) hide show
  1. package/dist/api-client/apollo-client.d.ts +102 -5
  2. package/dist/api-client/apollo-client.d.ts.map +1 -1
  3. package/dist/api-client/apollo-client.js +136 -5
  4. package/dist/api-client/apollo-client.js.map +1 -1
  5. package/dist/commands/import-agent.d.ts +2 -5
  6. package/dist/commands/import-agent.d.ts.map +1 -1
  7. package/dist/commands/import-agent.js +1 -1
  8. package/dist/commands/import-agent.js.map +1 -1
  9. package/dist/commands/init.d.ts.map +1 -1
  10. package/dist/commands/init.js +10 -3
  11. package/dist/commands/init.js.map +1 -1
  12. package/dist/commands/integration-mcp-test.d.ts +0 -2
  13. package/dist/commands/integration-mcp-test.d.ts.map +1 -1
  14. package/dist/commands/integration-mcp-test.js +41 -135
  15. package/dist/commands/integration-mcp-test.js.map +1 -1
  16. package/dist/commands/integration-mcp-url.d.ts +6 -7
  17. package/dist/commands/integration-mcp-url.d.ts.map +1 -1
  18. package/dist/commands/integration-mcp-url.js +10 -29
  19. package/dist/commands/integration-mcp-url.js.map +1 -1
  20. package/dist/commands/integration-toolkits.d.ts +4 -11
  21. package/dist/commands/integration-toolkits.d.ts.map +1 -1
  22. package/dist/commands/integration-toolkits.js +6 -28
  23. package/dist/commands/integration-toolkits.js.map +1 -1
  24. package/dist/commands/integration-tools.d.ts +5 -15
  25. package/dist/commands/integration-tools.d.ts.map +1 -1
  26. package/dist/commands/integration-tools.js +17 -63
  27. package/dist/commands/integration-tools.js.map +1 -1
  28. package/dist/commands/integration.d.ts +0 -1
  29. package/dist/commands/integration.d.ts.map +1 -1
  30. package/dist/commands/integration.js +62 -168
  31. package/dist/commands/integration.js.map +1 -1
  32. package/dist/commands/pull-agent.d.ts +2 -5
  33. package/dist/commands/pull-agent.d.ts.map +1 -1
  34. package/dist/commands/pull-agent.js +1 -1
  35. package/dist/commands/pull-agent.js.map +1 -1
  36. package/dist/errors/index.d.ts +9 -0
  37. package/dist/errors/index.d.ts.map +1 -1
  38. package/dist/errors/index.js +20 -9
  39. package/dist/errors/index.js.map +1 -1
  40. package/dist/index.js +21 -31
  41. package/dist/index.js.map +1 -1
  42. package/dist/services/integration.service.d.ts +73 -148
  43. package/dist/services/integration.service.d.ts.map +1 -1
  44. package/dist/services/integration.service.js +400 -559
  45. package/dist/services/integration.service.js.map +1 -1
  46. package/dist/services/pull-schema.service.d.ts +4 -5
  47. package/dist/services/pull-schema.service.d.ts.map +1 -1
  48. package/dist/services/pull-schema.service.js +12 -10
  49. package/dist/services/pull-schema.service.js.map +1 -1
  50. package/dist/ui/components/ErrorDisplay.d.ts.map +1 -1
  51. package/dist/ui/components/ErrorDisplay.js +16 -4
  52. package/dist/ui/components/ErrorDisplay.js.map +1 -1
  53. package/package.json +1 -2
@@ -1,43 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /**
3
- * integration command - Create and manage MCP integrations
4
- *
5
- * Supports interactive, scripted (some flags), and fully non-interactive
6
- * (`--full` or `--json`) modes.
7
- *
8
- * Interactive flow: type → config method → org → account → agent → name →
9
- * URL → auth → discover → select tools → confirm → save
10
- *
11
- * Usage:
12
- * aui integration Interactive menu
13
- * aui integration create Interactive MCP integration creation
14
- * aui integration create --name "My MCP" --url <url> --tools tool1,tool2
15
- * aui integration create --name "My MCP" --url <url> --all-tools --full
16
- * aui integration create --toolkit notion --name "Notion" --all-tools --full
17
- * aui integration discover --url <url> Discover tools from an MCP server
18
- *
19
- * `--full` makes the command fully non-interactive: it skips org/account/agent
20
- * selection prompts (uses session defaults) and the final confirmation
21
- * prompt. Required flags (`--name` + `--url` for manual; `--name` +
22
- * `--toolkit` for native; plus `--tools` or `--all-tools`) must be supplied;
23
- * missing values produce a clean validation error instead of a prompt.
24
- *
25
- * `--json` implies non-interactive and emits machine-readable output via
26
- * `outputJson` / `outputJsonError`.
27
- *
28
- * Composio (native) settings: `settings.composio.user_id` is the agent's
29
- * `network_id` (per backend `ComposioIntegrationSchema` →
30
- * `IntegrationMCPSettings`), so each agent owns its own Composio user
31
- * namespace. The MCP server is provisioned once on create; its caller-
32
- * stable id is persisted at `settings.composio.server_id` and the
33
- * provisioned HTTP URL is persisted at `settings.server_url` so the
34
- * runtime can hit the MCP endpoint without round-tripping Composio.
35
- */
36
- import { readFileSync } from "fs";
37
2
  import { render, Box, Text } from "ink";
38
3
  import inquirer from "inquirer";
39
4
  import chalk from "chalk";
40
- import { getAuthenticatedSession, discoverMCPTools, discoverComposioTools, saveIntegration as saveIntegrationSvc, resolveScopeIds, resolveNetworkCategoryId, listComposioToolkits, connectComposioToolkit, waitForComposioConnection, resetComposioClient, fetchComposioApiKey, getComposioToolkitAuthInfo, getComposioServerUrl, buildAuthFromFlags, parseTransportType, } from "../services/integration.service.js";
5
+ import { getAuthenticatedSession, discoverMCPTools, discoverComposioTools, saveIntegration as saveIntegrationSvc, resolveScopeIds, resolveNetworkCategoryId, listComposioToolkits, connectComposioToolkit, waitForComposioConnection, getComposioToolkitAuthInfo, getComposioServerUrl, buildAuthFromFlags, loadComposioCredentialsFile, parseTransportType, composioFailureLabel, composioFailureJson, } from "../services/integration.service.js";
41
6
  import { MCPToolList, IntegrationCreatedView, NativeIntegrationCreatedView, } from "../ui/views/IntegrationView.js";
42
7
  import { Header, Spinner, StatusLine, ErrorDisplay, } from "../ui/components/index.js";
43
8
  import { AUIClient } from "../api-client/index.js";
@@ -162,31 +127,6 @@ export async function promptDirectMCPAuth() {
162
127
  },
163
128
  };
164
129
  }
165
- // ─── BYO Credentials File Loader ───
166
- function loadCredentialsFile(filePath) {
167
- let raw;
168
- try {
169
- raw = JSON.parse(readFileSync(filePath, "utf-8"));
170
- }
171
- catch (err) {
172
- throw new Error(`Cannot read credentials file '${filePath}': ${err instanceof Error ? err.message : String(err)}`);
173
- }
174
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
175
- throw new Error(`Credentials file '${filePath}' must be a JSON object.`);
176
- }
177
- const obj = raw;
178
- const creds = {};
179
- if (obj.client_id)
180
- creds.clientId = String(obj.client_id);
181
- if (obj.client_secret)
182
- creds.clientSecret = String(obj.client_secret);
183
- if (obj.bearer_token)
184
- creds.bearerToken = String(obj.bearer_token);
185
- if (!creds.clientId && !creds.clientSecret && !creds.bearerToken) {
186
- throw new Error(`Credentials file '${filePath}' must contain at least one of: client_id, client_secret, bearer_token.`);
187
- }
188
- return creds;
189
- }
190
130
  // ─── Ink Rendering Helpers ───
191
131
  function log(node) {
192
132
  const { unmount } = render(node);
@@ -208,6 +148,22 @@ function startSpinner(label) {
208
148
  },
209
149
  };
210
150
  }
151
+ function saveIntegrationSuccessLabel(result) {
152
+ if (result.persistedVia === "local") {
153
+ return "Integration saved to integrations.aui.json";
154
+ }
155
+ if (result.persistedVia === "local_and_server") {
156
+ return "Integration created and saved to integrations.aui.json";
157
+ }
158
+ return "Integration created";
159
+ }
160
+ function saveIntegrationJsonExtras(result) {
161
+ return {
162
+ ...(result.persistedVia ? { persisted_via: result.persistedVia } : {}),
163
+ ...(result.agentMode ? { agent_mode: result.agentMode } : {}),
164
+ ...(result.suggestion ? { suggestion: result.suggestion } : {}),
165
+ };
166
+ }
211
167
  // ─── Shared: paginate-everything fetch helpers ───
212
168
  //
213
169
  // The org / account / agent / version pickers below list EVERY option
@@ -654,7 +610,7 @@ export async function integrationCreate(options = {}) {
654
610
  if (isManualNonInteractive) {
655
611
  configMethod = "manual";
656
612
  }
657
- else if (isNativeNonInteractive || options.toolkit || options.composioApiKey) {
613
+ else if (isNativeNonInteractive || options.toolkit) {
658
614
  configMethod = "native";
659
615
  }
660
616
  else if (isFull && options.url) {
@@ -964,10 +920,14 @@ async function manualIntegrationFlow(session, options, target) {
964
920
  },
965
921
  },
966
922
  response: result.data,
923
+ ...saveIntegrationJsonExtras(result),
967
924
  });
968
925
  return;
969
926
  }
970
- saveSpinner?.succeed("Integration created");
927
+ saveSpinner?.succeed(saveIntegrationSuccessLabel(result));
928
+ if (result.suggestion) {
929
+ log(_jsx(StatusLine, { kind: "info", label: result.suggestion }));
930
+ }
971
931
  log(_jsx(IntegrationCreatedView, { name: integrationName, serverUrl: serverUrl, toolCount: selectedToolNames.length, toolNames: selectedToolNames }));
972
932
  }
973
933
  catch (error) {
@@ -985,39 +945,6 @@ async function nativeIntegrationFlow(session, options, target) {
985
945
  const isNonInteractive = isFull ||
986
946
  !!(options.toolkit && options.name && (options.tools || options.allTools));
987
947
  const noPrompt = isJsonMode() || isFull;
988
- // ── Composio API Key (auto-fetched from backend, prompt as fallback) ──
989
- let apiKey = options.composioApiKey || process.env.COMPOSIO_API_KEY || "";
990
- if (!apiKey) {
991
- const fetchedKey = await fetchComposioApiKey(session);
992
- if (fetchedKey) {
993
- apiKey = fetchedKey;
994
- if (!isJsonMode()) {
995
- log(_jsx(StatusLine, { kind: "success", label: "Integration configuration loaded" }));
996
- }
997
- }
998
- else {
999
- if (noPrompt) {
1000
- const msg = "Integration API key not configured. Contact your administrator.";
1001
- if (isJsonMode()) {
1002
- outputJsonError({ code: "CONFIG_ERROR", message: msg });
1003
- }
1004
- else {
1005
- log(_jsx(ErrorDisplay, { message: msg, suggestion: "Pass --composio-api-key or have your administrator configure it." }));
1006
- }
1007
- return;
1008
- }
1009
- const { key } = await inquirer.prompt([
1010
- {
1011
- type: "password",
1012
- name: "key",
1013
- message: "Integration API Key:",
1014
- mask: "*",
1015
- validate: (input) => input.trim().length > 0 || "API key is required",
1016
- },
1017
- ]);
1018
- apiKey = key.trim();
1019
- }
1020
- }
1021
948
  // ── List & Select Toolkit ──
1022
949
  let selectedToolkit = null;
1023
950
  let toolkitSlug = options.toolkit || "";
@@ -1045,7 +972,7 @@ async function nativeIntegrationFlow(session, options, target) {
1045
972
  let toolkits;
1046
973
  let nextCursor;
1047
974
  try {
1048
- const result = await listComposioToolkits(apiKey, {
975
+ const result = await listComposioToolkits(session, scope, {
1049
976
  limit: 50,
1050
977
  search: searchTerm,
1051
978
  });
@@ -1054,20 +981,17 @@ async function nativeIntegrationFlow(session, options, target) {
1054
981
  toolkitSpinner.succeed(`Found ${toolkits.length} toolkits`);
1055
982
  }
1056
983
  catch (error) {
1057
- toolkitSpinner.fail("Failed to fetch toolkits");
1058
- const msg = error instanceof Error ? error.message : String(error);
1059
- if (msg.includes("401") || msg.includes("Unauthorized") || msg.includes("invalid")) {
1060
- log(_jsx(ErrorDisplay, { message: "Invalid API key.", suggestion: "Contact your administrator for a valid key." }));
984
+ toolkitSpinner.fail(composioFailureLabel(error, "Failed to fetch toolkits"));
985
+ if (isJsonMode()) {
986
+ outputJsonError(composioFailureJson(error));
1061
987
  }
1062
988
  else {
1063
- log(_jsx(ErrorDisplay, { error: error, message: "Failed to fetch toolkits." }));
989
+ log(_jsx(ErrorDisplay, { error: error }));
1064
990
  }
1065
- resetComposioClient();
1066
991
  return;
1067
992
  }
1068
993
  if (toolkits.length === 0) {
1069
- log(_jsx(ErrorDisplay, { message: searchTerm ? `No toolkits found matching "${searchTerm}".` : "No toolkits found.", suggestion: searchTerm ? "Try a different search term." : "Verify your API key is valid." }));
1070
- resetComposioClient();
994
+ log(_jsx(ErrorDisplay, { message: searchTerm ? `No toolkits found matching "${searchTerm}".` : "No toolkits found.", suggestion: searchTerm ? "Try a different search term." : "Verify your `aui login` session is still valid." }));
1071
995
  return;
1072
996
  }
1073
997
  // Load all pages upfront if user wants more, then present one list
@@ -1109,7 +1033,7 @@ async function nativeIntegrationFlow(session, options, target) {
1109
1033
  const previousCount = toolkits.length;
1110
1034
  const moreSpinner = startSpinner("Loading more toolkits...");
1111
1035
  try {
1112
- const more = await listComposioToolkits(apiKey, {
1036
+ const more = await listComposioToolkits(session, scope, {
1113
1037
  limit: 50,
1114
1038
  cursor: nextCursor,
1115
1039
  search: searchTerm,
@@ -1137,7 +1061,7 @@ async function nativeIntegrationFlow(session, options, target) {
1137
1061
  searchTerm = q;
1138
1062
  const searchSpinner = startSpinner(q ? `Searching for "${q}"...` : "Fetching toolkits...");
1139
1063
  try {
1140
- const result = await listComposioToolkits(apiKey, { limit: 50, search: q });
1064
+ const result = await listComposioToolkits(session, scope, { limit: 50, search: q });
1141
1065
  toolkits = result.items;
1142
1066
  nextCursor = result.nextCursor;
1143
1067
  searchSpinner.succeed(`Found ${toolkits.length} toolkits`);
@@ -1171,7 +1095,6 @@ async function nativeIntegrationFlow(session, options, target) {
1171
1095
  else {
1172
1096
  log(_jsx(ErrorDisplay, { message: msg, suggestion: "Pass --name when using --full." }));
1173
1097
  }
1174
- resetComposioClient();
1175
1098
  return;
1176
1099
  }
1177
1100
  const defaultName = selectedToolkit
@@ -1206,11 +1129,10 @@ async function nativeIntegrationFlow(session, options, target) {
1206
1129
  // ── Step 5: Auth Scheme Selection + BYO Credentials ──
1207
1130
  let authCredentials;
1208
1131
  let selectedAuthScheme;
1209
- let selectedSchemeIsManaged;
1210
1132
  {
1211
1133
  let authInfo = null;
1212
1134
  try {
1213
- authInfo = await getComposioToolkitAuthInfo(apiKey, toolkitSlug);
1135
+ authInfo = await getComposioToolkitAuthInfo(session, scope, toolkitSlug);
1214
1136
  }
1215
1137
  catch (err) {
1216
1138
  if (process.env.AUI_DEBUG) {
@@ -1231,7 +1153,6 @@ async function nativeIntegrationFlow(session, options, target) {
1231
1153
  else {
1232
1154
  log(_jsx(ErrorDisplay, { message: msg }));
1233
1155
  }
1234
- resetComposioClient();
1235
1156
  return;
1236
1157
  }
1237
1158
  pickedScheme = found;
@@ -1257,14 +1178,13 @@ async function nativeIntegrationFlow(session, options, target) {
1257
1178
  pickedScheme = chosen;
1258
1179
  }
1259
1180
  selectedAuthScheme = pickedScheme.scheme;
1260
- selectedSchemeIsManaged = pickedScheme.isManaged;
1261
1181
  // ── BYO credentials (only when scheme is not Composio-managed) ────────
1262
1182
  if (!pickedScheme.isManaged && pickedScheme.isOAuth) {
1263
1183
  if (noPrompt) {
1264
1184
  // Non-interactive: credentials file takes precedence over individual flags.
1265
1185
  if (options.composioCredentialsFile) {
1266
1186
  try {
1267
- authCredentials = loadCredentialsFile(options.composioCredentialsFile);
1187
+ authCredentials = loadComposioCredentialsFile(options.composioCredentialsFile);
1268
1188
  }
1269
1189
  catch (err) {
1270
1190
  const msg = err instanceof Error ? err.message : String(err);
@@ -1274,7 +1194,6 @@ async function nativeIntegrationFlow(session, options, target) {
1274
1194
  else {
1275
1195
  log(_jsx(ErrorDisplay, { message: msg }));
1276
1196
  }
1277
- resetComposioClient();
1278
1197
  return;
1279
1198
  }
1280
1199
  }
@@ -1293,7 +1212,6 @@ async function nativeIntegrationFlow(session, options, target) {
1293
1212
  else {
1294
1213
  log(_jsx(ErrorDisplay, { message: msg }));
1295
1214
  }
1296
- resetComposioClient();
1297
1215
  return;
1298
1216
  }
1299
1217
  }
@@ -1321,11 +1239,10 @@ async function nativeIntegrationFlow(session, options, target) {
1321
1239
  },
1322
1240
  ]);
1323
1241
  try {
1324
- authCredentials = loadCredentialsFile(filePath.trim());
1242
+ authCredentials = loadComposioCredentialsFile(filePath.trim());
1325
1243
  }
1326
1244
  catch (err) {
1327
1245
  log(_jsx(ErrorDisplay, { message: err instanceof Error ? err.message : String(err) }));
1328
- resetComposioClient();
1329
1246
  return;
1330
1247
  }
1331
1248
  }
@@ -1375,27 +1292,22 @@ async function nativeIntegrationFlow(session, options, target) {
1375
1292
  : startSpinner(`Connecting ${toolkitSlug}...`);
1376
1293
  let connectResult;
1377
1294
  try {
1378
- connectResult = await connectComposioToolkit(apiKey, composioUserId, toolkitSlug, {
1295
+ connectResult = await connectComposioToolkit(session, scope, composioUserId, toolkitSlug, {
1379
1296
  authCredentials,
1380
1297
  authScheme: selectedAuthScheme,
1381
- isManaged: selectedSchemeIsManaged,
1382
1298
  });
1383
1299
  connectSpinner?.succeed(connectResult.redirectUrl
1384
1300
  ? "Authentication link ready"
1385
1301
  : `Already connected — account ${connectResult.id}`);
1386
1302
  }
1387
1303
  catch (error) {
1388
- connectSpinner?.fail("Failed to connect toolkit");
1304
+ connectSpinner?.fail(composioFailureLabel(error, "Failed to connect toolkit"));
1389
1305
  if (isJsonMode()) {
1390
- outputJsonError({
1391
- code: "API_CLIENT_ERROR",
1392
- message: error instanceof Error ? error.message : String(error),
1393
- });
1306
+ outputJsonError(composioFailureJson(error));
1394
1307
  }
1395
1308
  else {
1396
- log(_jsx(ErrorDisplay, { error: error, message: "Failed to connect toolkit." }));
1309
+ log(_jsx(ErrorDisplay, { error: error }));
1397
1310
  }
1398
- resetComposioClient();
1399
1311
  return;
1400
1312
  }
1401
1313
  // ── Step 7: OAuth Authentication (if redirect required) ──
@@ -1415,7 +1327,6 @@ async function nativeIntegrationFlow(session, options, target) {
1415
1327
  else {
1416
1328
  log(_jsx(ErrorDisplay, { message: msg, suggestion: `Visit: ${connectResult.redirectUrl}` }));
1417
1329
  }
1418
- resetComposioClient();
1419
1330
  return;
1420
1331
  }
1421
1332
  log(_jsxs(Box, { flexDirection: "column", marginY: 1, children: [_jsxs(Text, { color: "cyan", children: [" ", "Opening browser for authentication..."] }), _jsxs(Text, { color: "gray", children: [" ", "If the browser doesn't open, visit:", "\n", " ", _jsx(Text, { color: "cyan", underline: true, children: connectResult.redirectUrl })] })] }));
@@ -1427,13 +1338,12 @@ async function nativeIntegrationFlow(session, options, target) {
1427
1338
  }
1428
1339
  const waitSpinner = startSpinner("Waiting for authentication (up to 2 minutes)...");
1429
1340
  try {
1430
- const connected = await waitForComposioConnection({ redirectUrl: connectResult.redirectUrl, connectionRequest: connectResult.connectionRequest }, 120000);
1341
+ const connected = await waitForComposioConnection(session, scope, composioUserId, toolkitSlug, 120_000);
1431
1342
  waitSpinner.succeed(`Authenticated — account ${connected.id}`);
1432
1343
  }
1433
- catch (error) {
1344
+ catch {
1434
1345
  waitSpinner.fail("Authentication timed out or failed");
1435
1346
  log(_jsx(ErrorDisplay, { message: "Authentication timed out.", suggestion: "Try again \u2014 make sure to complete the auth flow in the browser within 2 minutes." }));
1436
- resetComposioClient();
1437
1347
  return;
1438
1348
  }
1439
1349
  }
@@ -1446,33 +1356,25 @@ async function nativeIntegrationFlow(session, options, target) {
1446
1356
  : startSpinner(`Discovering tools for ${toolkitSlug}...`);
1447
1357
  let discoveredTools;
1448
1358
  try {
1449
- const result = await discoverComposioTools(apiKey, toolkitSlug);
1359
+ const result = await discoverComposioTools(session, scope, composioUserId, toolkitSlug);
1450
1360
  discoveredTools = result.tools;
1451
1361
  if (discoveredTools.length === 0) {
1452
1362
  if (isJsonMode()) {
1453
1363
  outputJsonError({ code: "API_CLIENT_ERROR", message: `No tools found for toolkit: ${toolkitSlug}` });
1454
1364
  }
1455
1365
  discoverSpinner?.fail("No tools found");
1456
- resetComposioClient();
1457
1366
  return;
1458
1367
  }
1459
- const totalLabel = result.totalItems
1460
- ? `${discoveredTools.length} of ${result.totalItems}`
1461
- : `${discoveredTools.length}`;
1462
- discoverSpinner?.succeed(`Discovered ${totalLabel} tools for ${toolkitSlug}`);
1368
+ discoverSpinner?.succeed(`Discovered ${discoveredTools.length} tools for ${toolkitSlug}`);
1463
1369
  }
1464
1370
  catch (error) {
1465
- discoverSpinner?.fail("Discovery failed");
1371
+ discoverSpinner?.fail(composioFailureLabel(error, "Discovery failed"));
1466
1372
  if (isJsonMode()) {
1467
- outputJsonError({
1468
- code: "API_CLIENT_ERROR",
1469
- message: `Discovery failed: ${error instanceof Error ? error.message : String(error)}`,
1470
- });
1373
+ outputJsonError(composioFailureJson(error));
1471
1374
  }
1472
1375
  else {
1473
- log(_jsx(ErrorDisplay, { error: error, message: "Failed to discover tools." }));
1376
+ log(_jsx(ErrorDisplay, { error: error }));
1474
1377
  }
1475
- resetComposioClient();
1476
1378
  return;
1477
1379
  }
1478
1380
  // ── Step 9: Select Tools ──
@@ -1489,7 +1391,6 @@ async function nativeIntegrationFlow(session, options, target) {
1489
1391
  else {
1490
1392
  log(_jsx(StatusLine, { kind: "error", label: msg }));
1491
1393
  }
1492
- resetComposioClient();
1493
1394
  return;
1494
1395
  }
1495
1396
  selectedToolNames = requestedTools;
@@ -1507,7 +1408,6 @@ async function nativeIntegrationFlow(session, options, target) {
1507
1408
  else {
1508
1409
  log(_jsx(ErrorDisplay, { message: msg, suggestion: suggestion }));
1509
1410
  }
1510
- resetComposioClient();
1511
1411
  return;
1512
1412
  }
1513
1413
  // Offer search before selecting if many tools
@@ -1538,16 +1438,14 @@ async function nativeIntegrationFlow(session, options, target) {
1538
1438
  },
1539
1439
  ]);
1540
1440
  const searchSpinner = startSpinner(`Searching tools for "${toolSearch.trim()}"...`);
1541
- try {
1542
- const searchResult = await discoverComposioTools(apiKey, toolkitSlug, {
1543
- query: toolSearch.trim(),
1544
- });
1545
- toolsToShow = searchResult.tools;
1546
- searchSpinner.succeed(`Found ${toolsToShow.length} matching tools`);
1547
- }
1548
- catch {
1549
- searchSpinner.fail("Search failed, showing all tools");
1550
- }
1441
+ // The new backend endpoint returns all tools for the (user, toolkit) pair
1442
+ // no server-side search so we filter the already-discovered list
1443
+ // locally rather than re-hitting the API.
1444
+ const term = toolSearch.trim().toLowerCase();
1445
+ const filtered = discoveredTools.filter((t) => t.name.toLowerCase().includes(term) ||
1446
+ (t.description || "").toLowerCase().includes(term));
1447
+ searchSpinner.succeed(`Found ${filtered.length} matching tools`);
1448
+ toolsToShow = filtered;
1551
1449
  if (toolsToShow.length === 0) {
1552
1450
  log(_jsx(StatusLine, { kind: "warning", label: "No tools match your search. Showing all tools." }));
1553
1451
  toolsToShow = discoveredTools;
@@ -1592,7 +1490,6 @@ async function nativeIntegrationFlow(session, options, target) {
1592
1490
  ]);
1593
1491
  if (!confirm) {
1594
1492
  log(_jsx(StatusLine, { kind: "muted", label: "Cancelled." }));
1595
- resetComposioClient();
1596
1493
  return;
1597
1494
  }
1598
1495
  }
@@ -1613,7 +1510,7 @@ async function nativeIntegrationFlow(session, options, target) {
1613
1510
  let mcpServerUrl;
1614
1511
  let mcpServerId;
1615
1512
  try {
1616
- const provisioned = await getComposioServerUrl(apiKey, {
1513
+ const provisioned = await getComposioServerUrl(session, scope, {
1617
1514
  composioUserId,
1618
1515
  toolkit: toolkitSlug,
1619
1516
  allowedTools: selectedToolNames,
@@ -1624,17 +1521,13 @@ async function nativeIntegrationFlow(session, options, target) {
1624
1521
  provisionSpinner?.succeed(`MCP server ready (${mcpServerId})`);
1625
1522
  }
1626
1523
  catch (error) {
1627
- provisionSpinner?.fail("Failed to provision MCP server");
1524
+ provisionSpinner?.fail(composioFailureLabel(error, "Failed to provision MCP server"));
1628
1525
  if (isJsonMode()) {
1629
- outputJsonError({
1630
- code: "API_CLIENT_ERROR",
1631
- message: `Failed to provision Composio MCP server: ${error instanceof Error ? error.message : String(error)}`,
1632
- });
1526
+ outputJsonError(composioFailureJson(error));
1633
1527
  }
1634
1528
  else {
1635
- log(_jsx(ErrorDisplay, { error: error, message: "Failed to provision Composio MCP server.", suggestion: "Re-run with AUI_DEBUG=1 to see the underlying Composio API call." }));
1529
+ log(_jsx(ErrorDisplay, { error: error }));
1636
1530
  }
1637
- resetComposioClient();
1638
1531
  return;
1639
1532
  }
1640
1533
  // ── Step 12: Save Integration ──
@@ -1668,7 +1561,6 @@ async function nativeIntegrationFlow(session, options, target) {
1668
1561
  }
1669
1562
  saveSpinner?.fail("Failed to create integration");
1670
1563
  log(_jsx(ErrorDisplay, { message: result.error || "Unknown error" }));
1671
- resetComposioClient();
1672
1564
  return;
1673
1565
  }
1674
1566
  if (isJsonMode()) {
@@ -1691,11 +1583,14 @@ async function nativeIntegrationFlow(session, options, target) {
1691
1583
  },
1692
1584
  },
1693
1585
  response: result.data,
1586
+ ...saveIntegrationJsonExtras(result),
1694
1587
  });
1695
- resetComposioClient();
1696
1588
  return;
1697
1589
  }
1698
- saveSpinner?.succeed("Integration created");
1590
+ saveSpinner?.succeed(saveIntegrationSuccessLabel(result));
1591
+ if (result.suggestion) {
1592
+ log(_jsx(StatusLine, { kind: "info", label: result.suggestion }));
1593
+ }
1699
1594
  log(_jsx(NativeIntegrationCreatedView, { name: integrationName, toolkitSlug: toolkitSlug, toolCount: selectedToolNames.length, toolNames: selectedToolNames, serverUrl: mcpServerUrl, serverId: mcpServerId }));
1700
1595
  }
1701
1596
  catch (error) {
@@ -1708,6 +1603,5 @@ async function nativeIntegrationFlow(session, options, target) {
1708
1603
  saveSpinner?.fail("Failed to create integration");
1709
1604
  log(_jsx(ErrorDisplay, { error: error, message: "Failed to create integration." }));
1710
1605
  }
1711
- resetComposioClient();
1712
1606
  }
1713
1607
  //# sourceMappingURL=integration.js.map