Skip to content

Commit 8acb65f

Browse files
committed
fix: resolve agent_protocol from project spec in invoke telemetry
The invoke telemetry was hard-coding agent_protocol='unknown'. Read the project spec before the telemetry wrapper so the actual protocol from the first runtime is used in the metric attributes.
1 parent d4efe1d commit 8acb65f

6 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/cli/commands/add/command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { renderTUI } from '../../tui';
12
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
23
import { requireProject, requireTTY } from '../../tui/guards';
3-
import { renderTUI } from '../../tui';
44
import type { Command } from '@commander-js/extra-typings';
55

66
export function registerAdd(program: Command): Command {

src/cli/commands/create/command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import {
2121
BuildType as TelemetryBuildType,
2222
standardize,
2323
} from '../../telemetry/schemas/common-shapes.js';
24+
import { renderTUI } from '../../tui';
2425
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
2526
import { requireTTY } from '../../tui/guards';
26-
import { renderTUI } from '../../tui';
2727
import { parseCommaSeparatedList } from '../shared/vpc-utils';
2828
import { type ProgressCallback, createProject, createProjectWithAgent, getDryRunInfo } from './action';
2929
import type { CreateOptions } from './types';

src/cli/commands/invoke/command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { ValidationError, serializeResult } from '../../../lib';
22
import { getErrorMessage } from '../../errors';
33
import { withCommandRunTelemetry } from '../../telemetry/cli-command-run.js';
44
import { AgentProtocol, AuthType, standardize } from '../../telemetry/schemas/common-shapes.js';
5+
import { renderTUI } from '../../tui';
56
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
67
import { requireProject, requireTTY } from '../../tui/guards';
7-
import { renderTUI } from '../../tui';
88
import { parseHeaderFlags } from '../shared/header-utils';
99
import { type InvokeContext, handleInvoke, loadInvokeConfig } from './action';
1010
import { resolvePrompt } from './resolve-prompt';

src/cli/commands/remove/command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ConfigIO, serializeResult, toError } from '../../../lib';
22
import { getErrorMessage } from '../../errors';
33
import { runCliCommand } from '../../telemetry/cli-command-run.js';
4+
import { renderTUI } from '../../tui';
45
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
56
import { requireProject, requireTTY } from '../../tui/guards';
6-
import { renderTUI } from '../../tui';
77
import type { RemoveAllOptions, RemoveResult } from './types';
88
import { validateRemoveAllOptions } from './validate';
99
import type { Command } from '@commander-js/extra-typings';

src/cli/telemetry/client-accessor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export class TelemetryClientAccessor {
2727
this.clientPromise = createClient(entrypoint, mode);
2828
}
2929

30-
31-
3230
static get(): Promise<TelemetryClient> {
3331
this.clientPromise ??= createClient('unknown');
3432
return this.clientPromise;

src/cli/tui/screens/invoke/useInvokeFlow.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,22 @@ export function useInvokeFlow(options: InvokeFlowOptions = {}): InvokeFlowState
116116
// Load config on mount
117117
useEffect(() => {
118118
const load = async () => {
119+
const configIO = new ConfigIO();
120+
const project = await configIO.readProjectSpec().catch(() => undefined);
121+
const firstProtocol = project?.runtimes?.[0]?.protocol ?? 'unknown';
122+
119123
const result = await withCommandRunTelemetry(
120124
'invoke',
121125
{
122126
has_stream: true,
123127
has_session_id: !!initialSessionId,
124128
auth_type: standardize(AuthType, initialBearerToken ? 'bearer_token' : 'sigv4'),
125-
agent_protocol: standardize(AgentProtocol, 'unknown'),
129+
agent_protocol: standardize(AgentProtocol, firstProtocol),
126130
},
127131
async () => {
128-
const configIO = new ConfigIO();
129-
const project = await configIO.readProjectSpec();
132+
if (!project) {
133+
return { success: false as const, error: new ResourceNotFoundError('No agentcore project found.') };
134+
}
130135
const deployedState = await configIO.readDeployedState();
131136
const awsTargets = await configIO.readAWSDeploymentTargets();
132137

@@ -143,7 +148,10 @@ export function useInvokeFlow(options: InvokeFlowOptions = {}): InvokeFlowState
143148
const targetConfig = awsTargets.find(t => t.name === targetName);
144149

145150
if (!targetConfig) {
146-
return { success: false as const, error: new ResourceNotFoundError(`Target config '${targetName}' not found`) };
151+
return {
152+
success: false as const,
153+
error: new ResourceNotFoundError(`Target config '${targetName}' not found`),
154+
};
147155
}
148156

149157
const runtimes: InvokeConfig['runtimes'] = [];
@@ -205,6 +213,7 @@ export function useInvokeFlow(options: InvokeFlowOptions = {}): InvokeFlowState
205213
}
206214
};
207215
void load();
216+
// eslint-disable-next-line react-hooks/exhaustive-deps
208217
}, [initialSessionId]);
209218

210219
const getMcpInvokeOptions = useCallback(() => {

0 commit comments

Comments
 (0)