1
import { describe, it, expect, vi, beforeEach } from 'vitest';
2
import { OpenAIAgentsProvider } from '../src';
3
-import { Tool } from '@composio/core';
3
+import { Tool, ExecuteToolFn } from '@composio/core';
4
import { tool as createOpenAIAgentTool } from '@openai/agents';
5
6
// Define an interface for our mocked OpenAI Agent tool
157
});
158
});
159
160
+ describe('strict mode', () => {
161
+ it('registers a strict schema with optional parameters kept as required-nullable', () => {
162
+ const strictProvider = new OpenAIAgentsProvider({ strict: true });
163
+ strictProvider._setExecuteToolFn(mockExecuteToolFn);
164
+ const wrapped = strictProvider.wrapTool(
165
+ {
166
+ ...mockTool,
167
+ inputParameters: {
168
+ type: 'object',
169
+ properties: {
170
+ input: { type: 'string' },
171
+ cfg: {
172
+ type: 'object',
173
+ properties: { url: { type: 'string' }, note: { type: 'string' } },
174
+ required: ['url'],
175
+ },
176
+ },
177
+ required: ['input'],
178
+ },
179
+ },
180
+ mockExecuteToolFn as ExecuteToolFn
181
+ ) as unknown as MockedOpenAIAgentTool;
182
+
183
+ expect(wrapped.strict).toBe(true);
184
+ expect(wrapped.parameters).toEqual({
185
+ type: 'object',
186
+ properties: {
187
+ input: { type: 'string' },
188
+ cfg: {
189
+ type: ['object', 'null'],
190
+ properties: { url: { type: 'string' }, note: { type: ['string', 'null'] } },
191
+ required: ['url', 'note'],
192
+ additionalProperties: false,
193
+ },
194
+ },
195
+ required: ['input', 'cfg'],
196
+ additionalProperties: false,
197
+ });
198
+ });
199
+
200
+ it('registers tools strict mode cannot express without strict', () => {
201
+ const strictProvider = new OpenAIAgentsProvider({ strict: true });
202
+ const wrapped = strictProvider.wrapTool(
203
+ {
204
+ ...mockTool,
205
+ inputParameters: {
206
+ type: 'object',
207
+ properties: { headers: { type: 'object', additionalProperties: { type: 'string' } } },
208
+ required: ['headers'],
209
+ },
210
+ },
211
+ mockExecuteToolFn as ExecuteToolFn
212
+ ) as unknown as MockedOpenAIAgentTool;
213
+
214
+ expect(wrapped.strict).toBe(false);
215
+ expect(wrapped.parameters).toEqual({
216
+ type: 'object',
217
+ properties: { headers: { type: 'object', additionalProperties: { type: 'string' } } },
218
+ required: ['headers'],
219
+ additionalProperties: true,
220
+ });
221
+ });
222
+
223
+ it('omits null arguments the tool schema rejects before executing under strict mode', async () => {
224
+ const strictProvider = new OpenAIAgentsProvider({ strict: true });
225
+ const wrapped = strictProvider.wrapTool(
226
+ {
227
+ ...mockTool,
228
+ inputParameters: {
229
+ type: 'object',
230
+ properties: {
231
+ input: { type: 'string' },
232
+ label: { type: 'string' },
233
+ clearable: { type: ['string', 'null'] },
234
+ },
235
+ required: ['input'],
236
+ },
237
+ },
238
+ mockExecuteToolFn as ExecuteToolFn
239
+ ) as unknown as MockedOpenAIAgentTool;
240
+
241
+ await wrapped.execute({ input: 'x', label: null, clearable: null });
242
+
243
+ expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, {
244
+ input: 'x',
245
+ clearable: null,
246
+ });
247
+ });
248
+ });
249
+
250
describe('wrapTools', () => {
251
it('should wrap multiple tools', () => {
252
const anotherTool: Tool = {