Skip to content

Commit 584012f

Browse files
committed
feat: review
1 parent 53ceb56 commit 584012f

File tree

5 files changed

+21
-44
lines changed

5 files changed

+21
-44
lines changed

src/resources/maestro/runs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MaestroRunRequest, MaestroRunResponse, RequestOptions, MaestroRunReques
44
import { DEFAULT_INTERVAL, DEFAULT_TIMEOUT } from '../../Constants';
55

66
const MAESTRO_PATH = '/maestro/runs';
7+
const MAESTRO_TERMINATED_RUN_STATUSES = ['completed', 'failed', 'requires_action'];
78

89
export class Runs extends APIResource {
910
async create(body: MaestroRunRequest): Promise<MaestroRunResponse> {
@@ -31,7 +32,7 @@ export class Runs extends APIResource {
3132

3233
while (Date.now() - startTime < timeout) {
3334
const response = await this.get(runId);
34-
if (response.status === 'completed') {
35+
if (MAESTRO_TERMINATED_RUN_STATUSES.includes(response.status)) {
3536
return response;
3637
}
3738

src/types/maestro/MaestroRunRequest.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,6 @@ type MaestroRunRequirement = {
1515

1616
type MaestroRunTool = HttpTool | MCPTool | FileSearchTool | WebSearchTool;
1717

18-
export type MaestroToolResources = {
19-
/*
20-
When provided, this object defines filters that AI21 Maestro will apply whenever it performs a file search.
21-
*/
22-
file_search?: {
23-
/*
24-
Restrict file search to these file IDs.
25-
*/
26-
file_ids?: string[];
27-
/*
28-
Restrict file search to files with these labels.
29-
*/
30-
labels?: string[];
31-
};
32-
/*
33-
When provided, this object defines filters that AI21 Maestro will apply whenever it performs a web search.
34-
*/
35-
web_search?: {
36-
/*
37-
Restrict web search to the specified URL prefixes.
38-
*/
39-
urls: string[];
40-
};
41-
};
42-
4318
type MaestroRunFirstPartyModel = 'jamba-mini' | 'jamba-large';
4419

4520
type MaestroRunManagedThirdPartyModel = string;
@@ -50,7 +25,7 @@ type MaestroRunBudget = 'low' | 'medium' | 'high';
5025

5126
type MaestroRunIncludeFields = 'data_sources' | 'requirements_result' | string;
5227

53-
type MaestroRunResponseLanguage =
28+
export type MaestroRunResponseLanguage =
5429
| 'arabic'
5530
| 'dutch'
5631
| 'english'
@@ -60,6 +35,7 @@ type MaestroRunResponseLanguage =
6035
| 'italian'
6136
| 'portuguese'
6237
| 'spanish'
38+
| 'unset'
6339
| string;
6440

6541
export interface MaestroRunRequest {
@@ -76,10 +52,6 @@ export interface MaestroRunRequest {
7652
*/
7753
tools?: MaestroRunTool[];
7854
/*
79-
A set of resources used by AI21 Maestro’s tools.
80-
*/
81-
tool_resources?: MaestroToolResources;
82-
/*
8355
The models to use for the maestro run.
8456
*/
8557
models?: MaestroRunModel[];

src/types/maestro/MaestroRunResponse.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { MaestroToolResources } from './MaestroRunRequest';
1+
import { FileSearchTool, WebSearchTool } from './MaestroTools';
22

3-
type MaestroRunResponseStatus = 'completed' | 'failed' | 'in_progress';
3+
type MaestroRunResponseStatus = 'completed' | 'failed' | 'in_progress' | 'requires_action';
44

55
type MaestroRunRequirementResult = {
66
score: number;
@@ -13,6 +13,11 @@ type MaestroRunRequirementResult = {
1313
};
1414
};
1515

16+
type DataSources = {
17+
file_search?: FileSearchTool;
18+
web_search?: WebSearchTool;
19+
};
20+
1621
export interface MaestroRunResponse {
1722
/*
1823
The ID of the maestro run for polling the status.
@@ -26,7 +31,7 @@ export interface MaestroRunResponse {
2631
/*
2732
Specifies the data sources used to retrieve contextual information for a run.
2833
*/
29-
data_sources: MaestroToolResources;
34+
data_sources: DataSources;
3035
/*
3136
Detailed results for each requirement.
3237
*/

src/types/maestro/MaestroTools.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ export interface MCPTool {
3737

3838
export interface FileSearchTool {
3939
type: 'file_search';
40-
file_ids?: string[];
40+
retrieval_similarity_threshold?: number;
4141
labels?: string[];
42+
labels_filter_mode?: 'AND' | 'OR';
43+
labels_filter?: Record<string, unknown>;
44+
file_ids?: string[];
45+
retrieval_strategy?: string;
46+
max_neighbors?: number;
4247
}
4348

4449
export interface WebSearchTool {

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,6 @@ describe('Maestro Runs', () => {
9494
allowed_tools: ['get_weather'],
9595
},
9696
],
97-
tool_resources: {
98-
file_search: {
99-
file_ids: ['file_123', 'file_456'],
100-
labels: ['ai', 'ml', 'nlp'],
101-
},
102-
web_search: {
103-
urls: ['https://arxiv.org', 'https://openai.com'],
104-
},
105-
},
10697
models: ['jamba-large', 'gpt-4o'],
10798
budget: 'high',
10899
include: ['data_sources', 'requirements_result'],
@@ -115,10 +106,12 @@ describe('Maestro Runs', () => {
115106
result: null,
116107
data_sources: {
117108
file_search: {
109+
type: 'file_search',
118110
file_ids: ['file_123', 'file_456'],
119111
labels: ['ai', 'ml', 'nlp'],
120112
},
121113
web_search: {
114+
type: 'web_search',
122115
urls: ['https://arxiv.org', 'https://openai.com'],
123116
},
124117
},
@@ -165,6 +158,7 @@ describe('Maestro Runs', () => {
165158
result: 'Here is a comprehensive summary of the latest AI developments...',
166159
data_sources: {
167160
web_search: {
161+
type: 'web_search',
168162
urls: ['https://arxiv.org', 'https://openai.com'],
169163
},
170164
},

0 commit comments

Comments
 (0)