Skip to content

Commit 9779f1c

Browse files
committed
update
1 parent d3521da commit 9779f1c

File tree

10 files changed

+168
-168
lines changed

10 files changed

+168
-168
lines changed

packages/agents-core/src/runImplementation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function processModelResponse<TContext>(
9393
tools
9494
.filter((t) => t.type === 'hosted_tool' && t.providerData?.type === 'mcp')
9595
.map((t) => t as HostedMCPTool)
96-
.map((t) => [t.providerData.serverLabel, t]),
96+
.map((t) => [t.providerData.server_label, t]),
9797
);
9898

9999
for (const output of modelResponse.output) {
@@ -114,7 +114,7 @@ export function processModelResponse<TContext>(
114114
const providerData =
115115
output.providerData as ProviderData.HostedMCPApprovalRequest;
116116

117-
const mcpServerLabel = providerData.serverLabel;
117+
const mcpServerLabel = providerData.server_label;
118118
const mcpServerTool = mcpToolMap.get(mcpServerLabel);
119119
if (typeof mcpServerTool === 'undefined') {
120120
const message = `MCP server (${mcpServerLabel}) not found in Agent (${agent.name})`;
@@ -142,7 +142,7 @@ export function processModelResponse<TContext>(
142142
requestItem: approvalItem,
143143
mcpTool: mcpServerTool,
144144
});
145-
if (!mcpServerTool.providerData.onApproval) {
145+
if (!mcpServerTool.providerData.on_approval) {
146146
// When onApproval function exists, it confirms the approval right after this.
147147
// Thus, this approval item must be appended only for the next turn interrpution patterns.
148148
items.push(approvalItem);
@@ -347,7 +347,7 @@ export async function executeInterruptedToolsAndSideEffects<TContext>(
347347
if (typeof approved !== 'undefined') {
348348
const providerData: ProviderData.HostedMCPApprovalResponse = {
349349
approve: approved,
350-
approvalRequestId,
350+
approval_request_id: approvalRequestId,
351351
reason: undefined,
352352
};
353353
// Tell Responses API server the approval result in the next turn
@@ -460,15 +460,15 @@ export async function executeToolsAndSideEffects<TContext>(
460460
.providerData as ProviderData.HostedMCPTool<TContext>;
461461
const requestData = approvalRequest.requestItem.rawItem
462462
.providerData as ProviderData.HostedMCPApprovalRequest;
463-
if (toolData.onApproval) {
463+
if (toolData.on_approval) {
464464
// synchronously handle the approval process here
465-
const approvalResult = await toolData.onApproval(
465+
const approvalResult = await toolData.on_approval(
466466
state._context,
467467
approvalRequest.requestItem,
468468
);
469469
const approvalResponseData: ProviderData.HostedMCPApprovalResponse = {
470470
approve: approvalResult.approve,
471-
approvalRequestId: requestData.id,
471+
approval_request_id: requestData.id,
472472
reason: approvalResult.reason,
473473
};
474474
newItems.push(

packages/agents-core/src/tool.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,19 @@ export function hostedMcpTool<Context = UnknownContext>(
154154
options.requireApproval === 'never'
155155
? {
156156
type: 'mcp',
157-
serverLabel: options.serverLabel,
158-
serverUrl: options.serverUrl,
159-
requireApproval: 'never',
157+
server_label: options.serverLabel,
158+
server_url: options.serverUrl,
159+
require_approval: 'never',
160160
}
161161
: {
162162
type: 'mcp',
163-
serverLabel: options.serverLabel,
164-
serverUrl: options.serverUrl,
165-
requireApproval: options.requireApproval,
166-
onApproval: options.onApproval,
163+
server_label: options.serverLabel,
164+
server_url: options.serverUrl,
165+
require_approval:
166+
typeof options.requireApproval === 'string'
167+
? options.requireApproval
168+
: buildRequireApproval(options.requireApproval),
169+
on_approval: options.onApproval,
167170
};
168171
return {
169172
type: 'hosted_tool',
@@ -575,3 +578,20 @@ export function tool<
575578
needsApproval,
576579
};
577580
}
581+
582+
function buildRequireApproval(requireApproval: {
583+
never?: { toolNames: string[] };
584+
always?: { toolNames: string[] };
585+
}): { never?: { tool_names: string[] }; always?: { tool_names: string[] } } {
586+
const result: {
587+
never?: { tool_names: string[] };
588+
always?: { tool_names: string[] };
589+
} = {};
590+
if (requireApproval.always) {
591+
result.always = { tool_names: requireApproval.always.toolNames };
592+
}
593+
if (requireApproval.never) {
594+
result.never = { tool_names: requireApproval.never.toolNames };
595+
}
596+
return result;
597+
}

packages/agents-core/src/types/providerData.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ import { UnknownContext } from './aliases';
66
*/
77
export type HostedMCPTool<Context = UnknownContext> = {
88
type: 'mcp';
9-
serverLabel: string;
10-
serverUrl: string;
9+
server_label: string;
10+
server_url: string;
1111
} & (
12-
| { requireApproval?: 'never'; onApproval?: never }
12+
| { require_approval?: 'never'; on_approval?: never }
1313
| {
14-
requireApproval:
14+
require_approval:
1515
| 'always'
1616
| {
17-
never?: { toolNames: string[] };
18-
always?: { toolNames: string[] };
17+
never?: { tool_names: string[] };
18+
always?: { tool_names: string[] };
1919
};
20-
onApproval?: HostedMCPApprovalFunction<Context>;
20+
on_approval?: HostedMCPApprovalFunction<Context>;
2121
}
2222
);
2323

2424
export type HostedMCPListTools = {
2525
id: string;
26-
serverLabel: string;
26+
server_label: string;
2727
tools: {
28-
inputSchema: unknown;
28+
input_schema: unknown;
2929
name: string;
3030
annotations?: unknown | null;
3131
description?: string | null;
@@ -36,7 +36,7 @@ export type HostedMCPCall = {
3636
id: string;
3737
arguments: string;
3838
name: string;
39-
serverLabel: string;
39+
server_label: string;
4040
error?: string | null;
4141
// excluding this large data field
4242
// output?: string | null;
@@ -46,12 +46,12 @@ export type HostedMCPApprovalRequest = {
4646
id: string;
4747
name: string;
4848
arguments: string;
49-
serverLabel: string;
49+
server_label: string;
5050
};
5151

5252
export type HostedMCPApprovalResponse = {
5353
id?: string;
5454
approve: boolean;
55-
approvalRequestId: string;
55+
approval_request_id: string;
5656
reason?: string;
5757
};

packages/agents-core/test/tool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('create a tool using hostedMcpTool utility', () => {
4646
expect(t.type).toBe('hosted_tool');
4747
expect(t.name).toBe('hosted_mcp');
4848
expect(t.providerData.type).toBe('mcp');
49-
expect(t.providerData.serverLabel).toBe('gitmcp');
49+
expect(t.providerData.server_label).toBe('gitmcp');
5050
});
5151
});
5252

packages/agents-openai/src/openaiResponsesModel.ts

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ import {
3333
ImageGenerationStatus,
3434
WebSearchStatus,
3535
} from './tools';
36-
import {
37-
camelOrSnakeToSnakeCase,
38-
snakeToCamelCase,
39-
} from './utils/providerData';
36+
import { camelOrSnakeToSnakeCase } from './utils/providerData';
4037
import { ProviderData } from '@openai/agents-core/types';
4138

4239
type ToolChoice = ToolChoiceOptions | ToolChoiceTypes | ToolChoiceFunction;
@@ -141,8 +138,8 @@ function converTool<_TContext = unknown>(
141138
return {
142139
tool: {
143140
type: 'web_search_preview',
144-
user_location: tool.providerData.userLocation,
145-
search_context_size: tool.providerData.searchContextSize,
141+
user_location: tool.providerData.user_location,
142+
search_context_size: tool.providerData.search_context_size,
146143
},
147144
include: undefined,
148145
};
@@ -151,16 +148,16 @@ function converTool<_TContext = unknown>(
151148
tool: {
152149
type: 'file_search',
153150
vector_store_ids:
154-
tool.providerData.vectorStoreIds ||
151+
tool.providerData.vector_store_ids ||
155152
// for backwards compatibility
156-
(typeof tool.providerData.vectorStoreId === 'string'
157-
? [tool.providerData.vectorStoreId]
158-
: tool.providerData.vectorStoreId),
159-
max_num_results: tool.providerData.maxNumResults,
160-
ranking_options: tool.providerData.rankingOptions,
153+
(typeof tool.providerData.vector_store_id === 'string'
154+
? [tool.providerData.vector_store_id]
155+
: tool.providerData.vector_store_id),
156+
max_num_results: tool.providerData.max_num_results,
157+
ranking_options: tool.providerData.ranking_options,
161158
filters: tool.providerData.filters,
162159
},
163-
include: tool.providerData.includeSearchResults
160+
include: tool.providerData.include_search_results
164161
? ['file_search_call.results']
165162
: undefined,
166163
};
@@ -177,12 +174,12 @@ function converTool<_TContext = unknown>(
177174
tool: {
178175
type: 'image_generation',
179176
background: tool.providerData.background,
180-
input_image_mask: tool.providerData.inputImageMask,
177+
input_image_mask: tool.providerData.input_image_mask,
181178
model: tool.providerData.model,
182179
moderation: tool.providerData.moderation,
183-
output_compression: tool.providerData.outputCompression,
184-
output_format: tool.providerData.outputFormat,
185-
partial_images: tool.providerData.partialImages,
180+
output_compression: tool.providerData.output_compression,
181+
output_format: tool.providerData.output_format,
182+
partial_images: tool.providerData.partial_images,
186183
quality: tool.providerData.quality,
187184
size: tool.providerData.size,
188185
},
@@ -192,10 +189,10 @@ function converTool<_TContext = unknown>(
192189
return {
193190
tool: {
194191
type: 'mcp',
195-
server_label: tool.providerData.serverLabel,
196-
server_url: tool.providerData.serverUrl,
192+
server_label: tool.providerData.server_label,
193+
server_url: tool.providerData.server_url,
197194
require_approval: convertMCPRequireApproval(
198-
tool.providerData.requireApproval,
195+
tool.providerData.require_approval,
199196
),
200197
},
201198
include: undefined,
@@ -212,7 +209,7 @@ function converTool<_TContext = unknown>(
212209
}
213210

214211
function convertMCPRequireApproval(
215-
requireApproval: ProviderData.HostedMCPTool['requireApproval'],
212+
requireApproval: ProviderData.HostedMCPTool['require_approval'],
216213
): OpenAI.Responses.Tool.Mcp.McpToolApprovalFilter | 'always' | 'never' | null {
217214
if (requireApproval === 'never' || requireApproval === undefined) {
218215
return 'never';
@@ -223,8 +220,8 @@ function convertMCPRequireApproval(
223220
}
224221

225222
return {
226-
never: { tool_names: requireApproval.never?.toolNames },
227-
always: { tool_names: requireApproval.always?.toolNames },
223+
never: { tool_names: requireApproval.never?.tool_names },
224+
always: { tool_names: requireApproval.always?.tool_names },
228225
};
229226
}
230227

@@ -519,7 +516,7 @@ function getInputItems(
519516
type: 'mcp_list_tools',
520517
id: item.id!,
521518
tools: camelOrSnakeToSnakeCase(providerData.tools) as any,
522-
server_label: providerData.serverLabel,
519+
server_label: providerData.server_label,
523520
error: providerData.error,
524521
...camelOrSnakeToSnakeCase(item.providerData),
525522
};
@@ -535,7 +532,7 @@ function getInputItems(
535532
id: providerData.id ?? item.id!,
536533
name: providerData.name,
537534
arguments: providerData.arguments,
538-
server_label: providerData.serverLabel,
535+
server_label: providerData.server_label,
539536
...camelOrSnakeToSnakeCase(item.providerData),
540537
};
541538
return entry;
@@ -549,7 +546,7 @@ function getInputItems(
549546
type: 'mcp_approval_response',
550547
id: providerData.id,
551548
approve: providerData.approve,
552-
approval_request_id: providerData.approvalRequestId,
549+
approval_request_id: providerData.approval_request_id,
553550
reason: providerData.reason,
554551
...camelOrSnakeToSnakeCase(providerData),
555552
};
@@ -564,7 +561,7 @@ function getInputItems(
564561
id: providerData.id ?? item.id!,
565562
name: providerData.name,
566563
arguments: providerData.arguments,
567-
server_label: providerData.serverLabel,
564+
server_label: providerData.server_label,
568565
error: providerData.error,
569566
// output, which can be a large text string, is optional here, so we don't include it
570567
// output: item.output,
@@ -636,7 +633,7 @@ function convertToOutputItem(
636633
role,
637634
content: content.map(convertToMessageContentItem),
638635
status,
639-
providerData: snakeToCamelCase(providerData),
636+
providerData,
640637
};
641638
} else if (
642639
item.type === 'file_search_call' ||
@@ -657,7 +654,7 @@ function convertToOutputItem(
657654
name: item.type,
658655
status,
659656
output: outputData,
660-
providerData: snakeToCamelCase(remainingItem),
657+
providerData: remainingItem,
661658
};
662659
return output;
663660
} else if (item.type === 'function_call') {
@@ -669,7 +666,7 @@ function convertToOutputItem(
669666
name,
670667
status,
671668
arguments: args,
672-
providerData: snakeToCamelCase(providerData),
669+
providerData,
673670
};
674671
return output;
675672
} else if (item.type === 'computer_call') {
@@ -680,7 +677,7 @@ function convertToOutputItem(
680677
callId: call_id,
681678
status,
682679
action,
683-
providerData: snakeToCamelCase(providerData),
680+
providerData,
684681
};
685682
return output;
686683
} else if (item.type === 'mcp_list_tools') {
@@ -691,7 +688,7 @@ function convertToOutputItem(
691688
name: item.type,
692689
status: 'completed',
693690
output: undefined,
694-
providerData: snakeToCamelCase(providerData),
691+
providerData,
695692
};
696693
return output;
697694
} else if (item.type === 'mcp_approval_request') {
@@ -702,7 +699,7 @@ function convertToOutputItem(
702699
name: 'mcp_approval_request',
703700
status: 'completed',
704701
output: undefined,
705-
providerData: snakeToCamelCase(providerData),
702+
providerData,
706703
};
707704
return output;
708705
} else if (item.type === 'mcp_call') {
@@ -714,7 +711,7 @@ function convertToOutputItem(
714711
name: item.type,
715712
status: 'completed',
716713
output: outputData || undefined,
717-
providerData: snakeToCamelCase(providerData),
714+
providerData,
718715
};
719716
return output;
720717
} else if (item.type === 'reasoning') {
@@ -729,17 +726,17 @@ function convertToOutputItem(
729726
return {
730727
type: 'input_text',
731728
text,
732-
providerData: snakeToCamelCase(remainingContent),
729+
providerData: remainingContent,
733730
};
734731
}),
735-
providerData: snakeToCamelCase(providerData),
732+
providerData,
736733
};
737734
return output;
738735
}
739736

740737
return {
741738
type: 'unknown',
742-
providerData: snakeToCamelCase(item),
739+
providerData: item,
743740
};
744741
});
745742
}

0 commit comments

Comments
 (0)