649
readonly specs: ReadonlyArray<ParallelExecuteSpec>;
650
};
651
652
+type ParallelExecuteResult =
653
+ | {
654
+ readonly slug: string;
655
+ readonly successful: true;
656
+ readonly version: string | null;
657
+ readonly schemaPath: string;
658
+ readonly inputSchema: Record<string, unknown>;
659
+ }
660
+ | {
661
+ readonly slug: string;
662
+ readonly successful: false;
663
+ readonly error: string;
664
+ };
665
+
666
type ResolvedExecuteContext = {
667
readonly ui: TerminalUI;
668
readonly executor: ToolsExecutor;
678
readonly executeOutputDir?: string;
679
};
680
681
+type ResolvedSchemaContext = {
682
+ readonly ui: TerminalUI;
683
+ readonly resolvedProject: {
684
+ readonly orgId: string;
685
+ readonly projectId: string;
686
+ readonly projectType: 'CONSUMER' | 'DEVELOPER';
687
+ readonly consumerUserId?: string;
688
+ };
689
+};
690
+
691
const emitCachedSchema = (
692
ui: TerminalUI,
693
slug: string,
781
} satisfies ResolvedExecuteContext;
782
});
783
784
+const resolveSchemaContext = (params: SharedRunToolsExecuteParams) =>
785
+ Effect.gen(function* () {
786
+ const resolvedProject = yield* resolveCommandProject({
787
+ mode: params.projectMode,
788
+ projectName:
789
+ params.surface === 'root' ? undefined : Option.getOrUndefined(params.projectName),
790
+ }).pipe(Effect.mapError(formatResolveCommandProjectError));
791
+ const ui = yield* TerminalUI;
792
+
793
+ return {
794
+ ui,
795
+ resolvedProject,
796
+ } satisfies ResolvedSchemaContext;
797
+ });
798
+
799
const runConnectedToolkitFailFast = (params: {
800
readonly slug: string;
801
readonly surface: 'root' | 'dev';
1151
Effect.gen(function* () {
1152
if (!(yield* requireAuth)) return;
1153
1115
- const context = yield* resolveExecuteContext(params);
1154
if (params.getSchema) {
1155
+ const context = yield* resolveSchemaContext(params);
1156
const definition = yield* getOrFetchToolInputDefinition(params.slug, {
1157
orgId: context.resolvedProject.orgId,
1158
projectId: context.resolvedProject.projectId,
1160
Effect.tapError(error =>
1161
emitExecuteFailureTelemetry({
1162
toolSlug: params.slug,
1124
- args: context.args,
1163
+ args: {},
1164
error,
1165
surface: params.surface,
1166
projectMode: params.projectMode,
1172
return;
1173
}
1174
1175
+ const context = yield* resolveExecuteContext(params);
1176
+
1177
yield* runConnectedToolkitFailFast({
1178
slug: params.slug,
1179
surface: params.surface,
1408
}
1409
});
1410
1411
+const runParallelSchemaFetchFromParsed = (params: ParsedParallelExecuteArgs) =>
1412
+ Effect.gen(function* () {
1413
+ const contexts = yield* Effect.forEach(
1414
+ params.specs,
1415
+ () =>
1416
+ resolveSchemaContext({
1417
+ userId: params.userId,
1418
+ projectName: params.projectName,
1419
+ surface: params.surface,
1420
+ projectMode: params.projectMode,
1421
+ getSchema: params.getSchema,
1422
+ dryRun: params.dryRun,
1423
+ skipConnectionCheck: params.skipConnectionCheck,
1424
+ skipToolParamsCheck: params.skipToolParamsCheck,
1425
+ skipChecks: params.skipChecks,
1426
+ }),
1427
+ { concurrency: 'unbounded' }
1428
+ );
1429
+ const entries = contexts.map((context, index) => ({
1430
+ context,
1431
+ spec: params.specs[index]!,
1432
+ }));
1433
+
1434
+ const ui = contexts[0]?.ui;
1435
+ const results = yield* Effect.forEach(
1436
+ entries,
1437
+ ({ context, spec }) =>
1438
+ Effect.gen(function* () {
1439
+ const definition = yield* getOrFetchToolInputDefinition(spec.slug, {
1440
+ orgId: context.resolvedProject.orgId,
1441
+ projectId: context.resolvedProject.projectId,
1442
+ });
1443
+ return {
1444
+ slug: spec.slug,
1445
+ successful: true,
1446
+ version: definition.version,
1447
+ schemaPath: definition.schemaPath,
1448
+ inputSchema: definition.schema,
1449
+ } satisfies Extract<
1450
+ ParallelExecuteResult,
1451
+ { readonly inputSchema: Record<string, unknown> }
1452
+ >;
1453
+ }).pipe(
1454
+ Effect.catchAll(error => {
1455
+ const mapped = mapComposioError({ error, toolSlug: spec.slug });
1456
+ return Effect.succeed({
1457
+ slug: spec.slug,
1458
+ successful: false,
1459
+ error: mapped.message,
1460
+ } satisfies Extract<ParallelExecuteResult, { readonly successful: false }>);
1461
+ })
1462
+ ),
1463
+ { concurrency: 'unbounded' }
1464
+ );
1465
+
1466
+ if (ui) {
1467
+ for (const result of results) {
1468
+ if (!result.successful) {
1469
+ yield* ui.log.error(`[${result.slug}] ${result.error}`);
1470
+ continue;
1471
+ }
1472
+
1473
+ yield* ui.log.step(`[${result.slug}] Schema fetched: ${result.schemaPath}`);
1474
+ }
1475
+
1476
+ const successful = results.every(result => result.successful);
1477
+ yield* ui.log.message(
1478
+ `Parallel execute completed: ${results.filter(result => result.successful).length}/${results.length} successful`
1479
+ );
1480
+ yield* ui.output(
1481
+ JSON.stringify(
1482
+ {
1483
+ successful,
1484
+ parallel: true,
1485
+ results,
1486
+ },
1487
+ ciRedactReplacer,
1488
+ 2
1489
+ )
1490
+ );
1491
+ if (!successful) {
1492
+ return yield* Effect.fail(
1493
+ new ToolExecutionError('One or more parallel tool executions failed.')
1494
+ );
1495
+ }
1496
+ }
1497
+ });
1498
+
1499
const runParallelToolsExecuteFromParsed = (params: ParsedParallelExecuteArgs) =>
1500
Effect.gen(function* () {
1501
if (!(yield* requireAuth)) return;
1502
1503
+ if (params.getSchema) {
1504
+ return yield* runParallelSchemaFetchFromParsed(params);
1505
+ }
1506
+
1507
const contexts = yield* Effect.forEach(
1508
params.specs,
1509
spec =>
1535
const toolSlug = spec.slug;
1536
1537
try {
1405
- if (params.getSchema) {
1406
- const definition = yield* getOrFetchToolInputDefinition(toolSlug, {
1407
- orgId: context.resolvedProject.orgId,
1408
- projectId: context.resolvedProject.projectId,
1409
- });
1410
- return {
1411
- slug: toolSlug,
1412
- successful: true,
1413
- version: definition.version,
1414
- schemaPath: definition.schemaPath,
1415
- inputSchema: definition.schema,
1416
- };
1417
- }
1418
-
1538
yield* checkConnectedToolkitOrFail({
1539
slug: toolSlug,
1540
resolvedProject: context.resolvedProject,