Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
621 changes: 311 additions & 310 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/cli/commands/add/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface AddGatewayOptions {
agentClientSecret?: string;
agents?: string;
semanticSearch?: boolean;
exceptionLevel?: string;
json?: boolean;
}

Expand Down
9 changes: 9 additions & 0 deletions src/cli/commands/add/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ConfigIO, findConfigRoot } from '../../../lib';
import {
AgentNameSchema,
BuildTypeSchema,
GatewayExceptionLevelSchema,
GatewayNameSchema,
ModelProviderSchema,
SDKFrameworkSchema,
Expand Down Expand Up @@ -208,6 +209,14 @@ export function validateAddGatewayOptions(options: AddGatewayOptions): Validatio
return { valid: false, error: 'Agent OAuth credentials are only valid with CUSTOM_JWT authorizer' };
}

// Validate exception level if provided
if (options.exceptionLevel) {
const levelResult = GatewayExceptionLevelSchema.safeParse(options.exceptionLevel);
if (!levelResult.success) {
return { valid: false, error: `Invalid exception level: ${options.exceptionLevel}. Use NONE or DEBUG` };
}
}

return { valid: true };
}

Expand Down
11 changes: 8 additions & 3 deletions src/cli/commands/deploy/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise<Dep
}

// Deploy
const hasGateways = mcpSpec?.agentCoreGateways && mcpSpec.agentCoreGateways.length > 0;
const hasGateways = (mcpSpec?.agentCoreGateways?.length ?? 0) > 0;
const deployStepName = hasGateways ? 'Deploying gateways...' : 'Deploy to AWS';
startStep(deployStepName);

Expand Down Expand Up @@ -419,9 +419,14 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise<Dep
// Post-deploy: Enable CloudWatch Transaction Search (non-blocking, silent)
const nextSteps = agentNames.length > 0 ? [...AGENT_NEXT_STEPS] : [...MEMORY_ONLY_NEXT_STEPS];
const notes: string[] = [];
if (agentNames.length > 0) {
if (agentNames.length > 0 || hasGateways) {
try {
const tsResult = await setupTransactionSearch({ region: target.region, accountId: target.account, agentNames });
const tsResult = await setupTransactionSearch({
region: target.region,
accountId: target.account,
agentNames,
hasGateways,
});
if (tsResult.error) {
logger.log(`Transaction search setup warning: ${tsResult.error}`, 'warn');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,36 @@ describe('setupTransactionSearch', () => {

expect(result).toEqual({ success: false, error: 'Insufficient permissions' });
});

it('triggers when hasGateways is true and agentNames is empty', async () => {
const result = await setupTransactionSearch({
region: 'us-west-2',
accountId: '111222333444',
agentNames: [],
hasGateways: true,
});
expect(mockEnableTransactionSearch).toHaveBeenCalledWith('us-west-2', '111222333444', 100);
expect(result).toEqual({ success: true });
});

it('skips when both agentNames empty and hasGateways false', async () => {
const result = await setupTransactionSearch({
region: 'us-east-1',
accountId: '123456789012',
agentNames: [],
hasGateways: false,
});
expect(result).toEqual({ success: true });
expect(mockEnableTransactionSearch).not.toHaveBeenCalled();
});

it('skips when agentNames empty and hasGateways undefined', async () => {
const result = await setupTransactionSearch({
region: 'us-east-1',
accountId: '123456789012',
agentNames: [],
});
expect(result).toEqual({ success: true });
expect(mockEnableTransactionSearch).not.toHaveBeenCalled();
});
});
3 changes: 2 additions & 1 deletion src/cli/operations/deploy/post-deploy-observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface TransactionSearchSetupOptions {
region: string;
accountId: string;
agentNames: string[];
hasGateways?: boolean;
}

export interface TransactionSearchSetupResult {
Expand All @@ -26,7 +27,7 @@ export async function setupTransactionSearch(
): Promise<TransactionSearchSetupResult> {
const { region, accountId, agentNames } = options;

if (agentNames.length === 0) {
if (agentNames.length === 0 && !options.hasGateways) {
return { success: true };
}

Expand Down
5 changes: 5 additions & 0 deletions src/cli/primitives/GatewayPrimitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface AddGatewayOptions {
agentClientSecret?: string;
agents?: string;
enableSemanticSearch?: boolean;
exceptionLevel?: string;
}

/**
Expand Down Expand Up @@ -158,6 +159,7 @@ export class GatewayPrimitive extends BasePrimitive<AddGatewayOptions, Removable
.option('--agent-client-secret <secret>', 'Agent OAuth client secret')
.option('--agents <agents>', 'Comma-separated agent names')
.option('--no-semantic-search', 'Disable semantic search for tool discovery')
.option('--exception-level <level>', 'Exception verbosity level', 'NONE')
.option('--json', 'Output as JSON')
.action(async (rawOptions: Record<string, string | boolean | undefined>) => {
const cliOptions = rawOptions as unknown as CLIAddGatewayOptions;
Expand Down Expand Up @@ -189,6 +191,7 @@ export class GatewayPrimitive extends BasePrimitive<AddGatewayOptions, Removable
agentClientSecret: cliOptions.agentClientSecret,
agents: cliOptions.agents,
enableSemanticSearch: cliOptions.semanticSearch !== false,
exceptionLevel: cliOptions.exceptionLevel,
});

if (cliOptions.json) {
Expand Down Expand Up @@ -286,6 +289,7 @@ export class GatewayPrimitive extends BasePrimitive<AddGatewayOptions, Removable
authorizerType: options.authorizerType,
jwtConfig: undefined,
enableSemanticSearch: options.enableSemanticSearch ?? true,
exceptionLevel: options.exceptionLevel === 'DEBUG' ? 'DEBUG' : 'NONE',
};

if (options.authorizerType === 'CUSTOM_JWT' && options.discoveryUrl) {
Expand Down Expand Up @@ -353,6 +357,7 @@ export class GatewayPrimitive extends BasePrimitive<AddGatewayOptions, Removable
authorizerType: config.authorizerType,
authorizerConfiguration: this.buildAuthorizerConfiguration(config),
enableSemanticSearch: config.enableSemanticSearch,
exceptionLevel: config.exceptionLevel,
};

mcpSpec.agentCoreGateways.push(gateway);
Expand Down
64 changes: 64 additions & 0 deletions src/cli/primitives/__tests__/GatewayPrimitive.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { AgentCoreMcpSpec } from '../../../schema';
import { GatewayPrimitive } from '../GatewayPrimitive';
import { beforeEach, describe, expect, it, vi } from 'vitest';

const { mockConfigExists, mockReadMcpSpec, mockWriteMcpSpec } = vi.hoisted(() => ({
mockConfigExists: vi.fn().mockReturnValue(true),
mockReadMcpSpec: vi.fn().mockResolvedValue({ agentCoreGateways: [] }),
mockWriteMcpSpec: vi.fn().mockResolvedValue(undefined),
}));

vi.mock('../../../lib', () => {
const MockConfigIO = vi.fn(function (this: Record<string, unknown>) {
this.configExists = mockConfigExists;
this.readMcpSpec = mockReadMcpSpec;
this.writeMcpSpec = mockWriteMcpSpec;
});
return {
ConfigIO: MockConfigIO,
findConfigRoot: vi.fn().mockReturnValue('/fake/root'),
setEnvVar: vi.fn().mockResolvedValue(undefined),
};
});

/** Extract the first gateway written to writeMcpSpec. */
function getWrittenGateway() {
expect(mockWriteMcpSpec).toHaveBeenCalledTimes(1);
const spec = mockWriteMcpSpec.mock.calls[0]![0] as AgentCoreMcpSpec;
const gw = spec.agentCoreGateways[0];
expect(gw).toBeDefined();
return gw!;
}

describe('GatewayPrimitive', () => {
let primitive: GatewayPrimitive;

beforeEach(() => {
vi.clearAllMocks();
mockReadMcpSpec.mockResolvedValue({ agentCoreGateways: [] });
primitive = new GatewayPrimitive();
});

describe('exceptionLevel', () => {
it('defaults to exceptionLevel NONE', async () => {
await primitive.add({ name: 'test-gw', authorizerType: 'NONE' });

const gw = getWrittenGateway();
expect(gw.exceptionLevel).toBe('NONE');
});

it('exceptionLevel DEBUG passes through', async () => {
await primitive.add({ name: 'test-gw', authorizerType: 'NONE', exceptionLevel: 'DEBUG' });

const gw = getWrittenGateway();
expect(gw.exceptionLevel).toBe('DEBUG');
});

it('invalid exceptionLevel falls back to NONE', async () => {
await primitive.add({ name: 'test-gw', authorizerType: 'NONE', exceptionLevel: 'VERBOSE' });

const gw = getWrittenGateway();
expect(gw.exceptionLevel).toBe('NONE');
});
});
});
1 change: 1 addition & 0 deletions src/cli/tui/hooks/useCreateMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function useCreateGateway() {
agentClientId: config.jwtConfig?.agentClientId,
agentClientSecret: config.jwtConfig?.agentClientSecret,
enableSemanticSearch: config.enableSemanticSearch,
exceptionLevel: config.exceptionLevel,
});
if (!addResult.success) {
throw new Error(addResult.error ?? 'Failed to create gateway');
Expand Down
11 changes: 10 additions & 1 deletion src/cli/tui/screens/deploy/useDeployFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,21 @@ export function useDeployFlow(options: DeployFlowOptions = {}): DeployFlowState
const agentNames = context?.projectSpec.agents?.map((a: { name: string }) => a.name) ?? [];
const targetRegion = context?.awsTargets[0]?.region;
const targetAccount = context?.awsTargets[0]?.account;
if (agentNames.length > 0 && targetRegion && targetAccount) {
let hasGateways = false;
try {
const tsConfigIO = new ConfigIO();
const mcpSpec = await tsConfigIO.readMcpSpec();
hasGateways = (mcpSpec?.agentCoreGateways?.length ?? 0) > 0;
} catch {
// No mcp.json or invalid -- no gateways
}
if ((agentNames.length > 0 || hasGateways) && targetRegion && targetAccount) {
try {
const tsResult = await setupTransactionSearch({
region: targetRegion,
accountId: targetAccount,
agentNames,
hasGateways,
});
if (tsResult.error) {
logger.log(`Transaction search setup warning: ${tsResult.error}`, 'warn');
Expand Down
18 changes: 15 additions & 3 deletions src/cli/tui/screens/mcp/AddGatewayScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { HELP_TEXT } from '../../constants';
import { useListNavigation, useMultiSelectNavigation } from '../../hooks';
import { generateUniqueName } from '../../utils';
import type { AddGatewayConfig } from './types';
import { AUTHORIZER_TYPE_OPTIONS, GATEWAY_STEP_LABELS, SEMANTIC_SEARCH_ITEM_ID } from './types';
import {
AUTHORIZER_TYPE_OPTIONS,
EXCEPTION_LEVEL_ITEM_ID,
GATEWAY_STEP_LABELS,
SEMANTIC_SEARCH_ITEM_ID,
} from './types';
import { useAddGatewayWizard } from './useAddGatewayWizard';
import { Box, Text } from 'ink';
import React, { useMemo, useState } from 'react';
Expand Down Expand Up @@ -51,7 +56,10 @@ export function AddGatewayScreen({ onComplete, onExit, existingGateways, unassig
);

const advancedConfigItems: SelectableItem[] = useMemo(
() => [{ id: SEMANTIC_SEARCH_ITEM_ID, title: 'Semantic Search' }],
() => [
{ id: SEMANTIC_SEARCH_ITEM_ID, title: 'Semantic Search' },
{ id: EXCEPTION_LEVEL_ITEM_ID, title: 'Debug Exception Level' },
],
[]
);

Expand Down Expand Up @@ -83,7 +91,10 @@ export function AddGatewayScreen({ onComplete, onExit, existingGateways, unassig
getId: item => item.id,
initialSelectedIds: INITIAL_ADVANCED_SELECTED,
onConfirm: selectedIds =>
wizard.setAdvancedConfig({ enableSemanticSearch: selectedIds.includes(SEMANTIC_SEARCH_ITEM_ID) }),
wizard.setAdvancedConfig({
enableSemanticSearch: selectedIds.includes(SEMANTIC_SEARCH_ITEM_ID),
exceptionLevel: selectedIds.includes(EXCEPTION_LEVEL_ITEM_ID) ? 'DEBUG' : 'NONE',
}),
onExit: () => wizard.goBack(),
isActive: isAdvancedConfigStep,
requireSelection: false,
Expand Down Expand Up @@ -273,6 +284,7 @@ export function AddGatewayScreen({ onComplete, onExit, existingGateways, unassig
: '(none)',
},
{ label: 'Semantic Search', value: wizard.config.enableSemanticSearch ? 'Enabled' : 'Disabled' },
{ label: 'Exception Level', value: wizard.config.exceptionLevel === 'DEBUG' ? 'Debug' : 'None' },
]}
/>
)}
Expand Down
Loading
Loading