Skip to content

Commit 53ceb56

Browse files
committed
feat: added new tools
1 parent 4b94d95 commit 53ceb56

File tree

6 files changed

+89
-14
lines changed

6 files changed

+89
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ console.log(result);
134134

135135
### Create and Poll (Recommended)
136136

137-
For convenience, you can use `create_and_poll()` which automatically waits for completion:
137+
For convenience, you can use `createAndPoll()` which automatically waits for completion:
138138

139139
```typescript
140-
const result = await client.beta.maestro.runs.create_and_poll(
140+
const result = await client.beta.maestro.runs.createAndPoll(
141141
{
142142
input: 'Write a comprehensive report on AI trends in 2024',
143143
tools: ['web_search'],
@@ -157,7 +157,7 @@ console.log(result.result);
157157
Maestro supports various advanced configurations:
158158

159159
```typescript
160-
const advancedRun = await client.beta.maestro.runs.create_and_poll({
160+
const advancedRun = await client.beta.maestro.runs.createAndPoll({
161161
input: 'Research sustainable energy solutions',
162162

163163
// Specify tools to use

examples/studio/maestro/maestro-run-create-and-poll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const INTERVAL = 1500;
66
async function main() {
77
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
88

9-
const response = await client.beta.maestro.runs.create_and_poll(
9+
const response = await client.beta.maestro.runs.createAndPoll(
1010
{
1111
input: 'Write a poem about the ocean',
1212
requirements: [

src/resources/maestro/runs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class Runs extends APIResource {
4141
throw new TimeoutError(`Maestro run ${runId}`, timeout);
4242
}
4343

44-
async create_and_poll(
44+
async createAndPoll(
4545
body: MaestroRunRequest,
4646
options?: MaestroRunRequestOptions,
4747
): Promise<MaestroRunResponse> {

src/types/maestro/MaestroRunRequest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { FileSearchTool, HttpTool, MCPTool, WebSearchTool } from './MaestroTools';
2+
13
type MaestroRunInputObject = {
24
role: string;
35
content: string;
@@ -11,7 +13,7 @@ type MaestroRunRequirement = {
1113
isMandatory?: boolean;
1214
};
1315

14-
type MaestroRunTool = 'file_search' | 'web_search';
16+
type MaestroRunTool = HttpTool | MCPTool | FileSearchTool | WebSearchTool;
1517

1618
export type MaestroToolResources = {
1719
/*

src/types/maestro/MaestroTools.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
interface HttpToolFunctionParametersProperty {
2+
type: string;
3+
description: string;
4+
}
5+
6+
interface HttpToolFunctionParameters {
7+
type: 'object';
8+
properties: Record<string, HttpToolFunctionParametersProperty>;
9+
required: string[];
10+
additional_properties?: boolean;
11+
}
12+
13+
interface HttpToolFunction {
14+
name: string;
15+
description: string;
16+
parameters: HttpToolFunctionParameters;
17+
}
18+
19+
interface HttpToolEndpoint {
20+
url: string;
21+
headers?: Record<string, string>;
22+
}
23+
24+
export interface HttpTool {
25+
type: 'http';
26+
function: HttpToolFunction;
27+
endpoint: HttpToolEndpoint;
28+
}
29+
30+
export interface MCPTool {
31+
type: 'mcp';
32+
server_label: string;
33+
server_url: string;
34+
headers?: Record<string, string>;
35+
allowed_tools?: string[];
36+
}
37+
38+
export interface FileSearchTool {
39+
type: 'file_search';
40+
file_ids?: string[];
41+
labels?: string[];
42+
}
43+
44+
export interface WebSearchTool {
45+
type: 'web_search';
46+
urls?: string[];
47+
}

tests/unittests/resources/maestro/runs.test.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,33 @@ describe('Maestro Runs', () => {
6767
},
6868
{ name: 'completeness', description: 'Cover all major areas', isMandatory: false },
6969
],
70-
tools: ['web_search', 'file_search'],
70+
tools: [
71+
{ type: 'web_search', urls: ['https://arxiv.org', 'https://openai.com'] },
72+
{ type: 'file_search', file_ids: ['file_123', 'file_456'], labels: ['ai', 'ml', 'nlp'] },
73+
{
74+
type: 'http',
75+
function: {
76+
name: 'get_weather',
77+
description: 'Get the weather for a given city',
78+
parameters: {
79+
type: 'object',
80+
properties: { city: { type: 'string', description: 'The city to get the weather for' } },
81+
required: ['city'],
82+
},
83+
},
84+
endpoint: {
85+
url: 'https://api.openweathermap.org/data/2.5/weather',
86+
headers: { Authorization: 'Bearer 1234567890' },
87+
},
88+
},
89+
{
90+
type: 'mcp',
91+
server_label: 'openai',
92+
server_url: 'https://my-mcp-server.com',
93+
headers: { Authorization: 'Bearer 1234567890' },
94+
allowed_tools: ['get_weather'],
95+
},
96+
],
7197
tool_resources: {
7298
file_search: {
7399
file_ids: ['file_123', 'file_456'],
@@ -174,7 +200,7 @@ describe('Maestro Runs', () => {
174200
});
175201
});
176202

177-
describe('create_and_poll', () => {
203+
describe('createAndPoll', () => {
178204
it('should create and poll until completion with default options', async () => {
179205
const body: Models.MaestroRunRequest = {
180206
input: 'Test input',
@@ -199,7 +225,7 @@ describe('Maestro Runs', () => {
199225
mockClient.post.mockResolvedValue(createResponse);
200226
mockClient.get.mockResolvedValue(completedResponse);
201227

202-
const response = await runs.create_and_poll(body);
228+
const response = await runs.createAndPoll(body);
203229

204230
expect(mockClient.post).toHaveBeenCalledWith('/maestro/runs', { body });
205231
expect(mockClient.get).toHaveBeenCalledWith('/maestro/runs/run_123');
@@ -235,14 +261,14 @@ describe('Maestro Runs', () => {
235261
mockClient.post.mockResolvedValue(createResponse);
236262
mockClient.get.mockResolvedValue(completedResponse);
237263

238-
const response = await runs.create_and_poll(body, options);
264+
const response = await runs.createAndPoll(body, options);
239265

240266
expect(mockClient.post).toHaveBeenCalledWith('/maestro/runs', { body });
241267
expect(mockClient.get).toHaveBeenCalledWith('/maestro/runs/run_123');
242268
expect(response).toEqual(completedResponse);
243269
});
244270

245-
it('should call create_and_poll with correct parameters', async () => {
271+
it('should call createAndPoll with correct parameters', async () => {
246272
const body: Models.MaestroRunRequest = {
247273
input: 'Test input',
248274
};
@@ -271,7 +297,7 @@ describe('Maestro Runs', () => {
271297
mockClient.post.mockResolvedValue(createResponse);
272298
mockClient.get.mockResolvedValue(completedResponse);
273299

274-
const response = await runs.create_and_poll(body, options);
300+
const response = await runs.createAndPoll(body, options);
275301

276302
expect(mockClient.post).toHaveBeenCalledWith('/maestro/runs', { body });
277303
expect(mockClient.get).toHaveBeenCalledWith('/maestro/runs/run_123');
@@ -286,7 +312,7 @@ describe('Maestro Runs', () => {
286312
const error = new AI21Error();
287313
mockClient.post.mockRejectedValue(error);
288314

289-
await expect(runs.create_and_poll(body)).rejects.toThrow();
315+
await expect(runs.createAndPoll(body)).rejects.toThrow();
290316
});
291317

292318
it('should handle polling errors', async () => {
@@ -306,7 +332,7 @@ describe('Maestro Runs', () => {
306332
mockClient.post.mockResolvedValue(createResponse);
307333
mockClient.get.mockRejectedValue(error);
308334

309-
await expect(runs.create_and_poll(body)).rejects.toThrow();
335+
await expect(runs.createAndPoll(body)).rejects.toThrow();
310336
});
311337
});
312338

0 commit comments

Comments
 (0)