• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #6244

10 Feb 2026 05:27PM UTC coverage: 40.749% (+22.6%) from 18.192%
#6244

push

github

web-flow
fix(boxsdkgen): Move assigning default values from builder constructor to `build()` method (box/box-codegen#922) (#1712)

0 of 1677 new or added lines in 569 files covered. (0.0%)

2146 existing lines in 544 files now uncovered.

7382 of 18116 relevant lines covered (40.75%)

0.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/box/sdkgen/managers/ai/AiManager.java
1
package com.box.sdkgen.managers.ai;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8

9
import com.box.sdkgen.networking.auth.Authentication;
10
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
11
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
12
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
13
import com.box.sdkgen.networking.network.NetworkSession;
14
import com.box.sdkgen.schemas.aiagent.AiAgent;
15
import com.box.sdkgen.schemas.aiask.AiAsk;
16
import com.box.sdkgen.schemas.aiextract.AiExtract;
17
import com.box.sdkgen.schemas.aiextractstructured.AiExtractStructured;
18
import com.box.sdkgen.schemas.aiextractstructuredresponse.AiExtractStructuredResponse;
19
import com.box.sdkgen.schemas.airesponse.AiResponse;
20
import com.box.sdkgen.schemas.airesponsefull.AiResponseFull;
21
import com.box.sdkgen.schemas.aitextgen.AiTextGen;
22
import com.box.sdkgen.serialization.json.JsonManager;
23
import java.util.Map;
24

25
public class AiManager {
26

27
  public Authentication auth;
28

29
  public NetworkSession networkSession;
30

31
  public AiManager() {
×
32
    this.networkSession = new NetworkSession();
×
33
  }
×
34

35
  protected AiManager(Builder builder) {
×
36
    this.auth = builder.auth;
×
37
    this.networkSession = builder.networkSession;
×
38
  }
×
39

40
  /**
41
   * Sends an AI request to supported LLMs and returns an answer specifically focused on the user's
42
   * question given the provided context.
43
   *
44
   * @param requestBody Request body of createAiAsk method
45
   */
46
  public AiResponseFull createAiAsk(AiAsk requestBody) {
47
    return createAiAsk(requestBody, new CreateAiAskHeaders());
×
48
  }
49

50
  /**
51
   * Sends an AI request to supported LLMs and returns an answer specifically focused on the user's
52
   * question given the provided context.
53
   *
54
   * @param requestBody Request body of createAiAsk method
55
   * @param headers Headers of createAiAsk method
56
   */
57
  public AiResponseFull createAiAsk(AiAsk requestBody, CreateAiAskHeaders headers) {
58
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
59
    FetchResponse response =
×
60
        this.networkSession
61
            .getNetworkClient()
×
62
            .fetch(
×
63
                new FetchOptions.Builder(
64
                        String.join(
×
65
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/ask"),
×
66
                        "POST")
67
                    .headers(headersMap)
×
68
                    .data(JsonManager.serialize(requestBody))
×
69
                    .contentType("application/json")
×
70
                    .responseFormat(ResponseFormat.JSON)
×
71
                    .auth(this.auth)
×
72
                    .networkSession(this.networkSession)
×
73
                    .build());
×
74
    if (convertToString(response.getStatus()).equals("204")) {
×
75
      return null;
×
76
    }
77
    return JsonManager.deserialize(response.getData(), AiResponseFull.class);
×
78
  }
79

80
  /**
81
   * Sends an AI request to supported Large Language Models (LLMs) and returns generated text based
82
   * on the provided prompt.
83
   *
84
   * @param requestBody Request body of createAiTextGen method
85
   */
86
  public AiResponse createAiTextGen(AiTextGen requestBody) {
87
    return createAiTextGen(requestBody, new CreateAiTextGenHeaders());
×
88
  }
89

90
  /**
91
   * Sends an AI request to supported Large Language Models (LLMs) and returns generated text based
92
   * on the provided prompt.
93
   *
94
   * @param requestBody Request body of createAiTextGen method
95
   * @param headers Headers of createAiTextGen method
96
   */
97
  public AiResponse createAiTextGen(AiTextGen requestBody, CreateAiTextGenHeaders headers) {
98
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
99
    FetchResponse response =
×
100
        this.networkSession
101
            .getNetworkClient()
×
102
            .fetch(
×
103
                new FetchOptions.Builder(
104
                        String.join(
×
105
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/text_gen"),
×
106
                        "POST")
107
                    .headers(headersMap)
×
108
                    .data(JsonManager.serialize(requestBody))
×
109
                    .contentType("application/json")
×
110
                    .responseFormat(ResponseFormat.JSON)
×
111
                    .auth(this.auth)
×
112
                    .networkSession(this.networkSession)
×
113
                    .build());
×
114
    return JsonManager.deserialize(response.getData(), AiResponse.class);
×
115
  }
116

117
  /**
118
   * Get the AI agent default config.
119
   *
120
   * @param queryParams Query parameters of getAiAgentDefaultConfig method
121
   */
122
  public AiAgent getAiAgentDefaultConfig(GetAiAgentDefaultConfigQueryParams queryParams) {
123
    return getAiAgentDefaultConfig(queryParams, new GetAiAgentDefaultConfigHeaders());
×
124
  }
125

126
  /**
127
   * Get the AI agent default config.
128
   *
129
   * @param queryParams Query parameters of getAiAgentDefaultConfig method
130
   * @param headers Headers of getAiAgentDefaultConfig method
131
   */
132
  public AiAgent getAiAgentDefaultConfig(
133
      GetAiAgentDefaultConfigQueryParams queryParams, GetAiAgentDefaultConfigHeaders headers) {
134
    Map<String, String> queryParamsMap =
×
135
        prepareParams(
×
136
            mapOf(
×
137
                entryOf("mode", convertToString(queryParams.getMode())),
×
138
                entryOf("language", convertToString(queryParams.getLanguage())),
×
139
                entryOf("model", convertToString(queryParams.getModel()))));
×
140
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
141
    FetchResponse response =
×
142
        this.networkSession
143
            .getNetworkClient()
×
144
            .fetch(
×
145
                new FetchOptions.Builder(
146
                        String.join(
×
147
                            "",
148
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
149
                            "/2.0/ai_agent_default"),
150
                        "GET")
151
                    .params(queryParamsMap)
×
152
                    .headers(headersMap)
×
153
                    .responseFormat(ResponseFormat.JSON)
×
154
                    .auth(this.auth)
×
155
                    .networkSession(this.networkSession)
×
156
                    .build());
×
157
    return JsonManager.deserialize(response.getData(), AiAgent.class);
×
158
  }
159

160
  /**
161
   * Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of
162
   * key-value pairs. In this request, both the prompt and the output can be freeform. Metadata
163
   * template setup before sending the request is not required.
164
   *
165
   * @param requestBody Request body of createAiExtract method
166
   */
167
  public AiResponse createAiExtract(AiExtract requestBody) {
168
    return createAiExtract(requestBody, new CreateAiExtractHeaders());
×
169
  }
170

171
  /**
172
   * Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of
173
   * key-value pairs. In this request, both the prompt and the output can be freeform. Metadata
174
   * template setup before sending the request is not required.
175
   *
176
   * @param requestBody Request body of createAiExtract method
177
   * @param headers Headers of createAiExtract method
178
   */
179
  public AiResponse createAiExtract(AiExtract requestBody, CreateAiExtractHeaders headers) {
180
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
181
    FetchResponse response =
×
182
        this.networkSession
183
            .getNetworkClient()
×
184
            .fetch(
×
185
                new FetchOptions.Builder(
186
                        String.join(
×
187
                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/ai/extract"),
×
188
                        "POST")
189
                    .headers(headersMap)
×
190
                    .data(JsonManager.serialize(requestBody))
×
191
                    .contentType("application/json")
×
192
                    .responseFormat(ResponseFormat.JSON)
×
193
                    .auth(this.auth)
×
194
                    .networkSession(this.networkSession)
×
195
                    .build());
×
196
    return JsonManager.deserialize(response.getData(), AiResponse.class);
×
197
  }
198

199
  /**
200
   * Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as
201
   * a set of key-value pairs.
202
   *
203
   * <p>To define the extraction structure, provide either a metadata template or a list of fields.
204
   * To learn more about creating templates, see [Creating metadata templates in the Admin
205
   * Console](https://support.box.com/hc/en-us/articles/360044194033-Customizing-Metadata-Templates)
206
   * or use the [metadata template API](https://developer.box.com/guides/metadata/templates/create).
207
   *
208
   * <p>This endpoint also supports [Enhanced Extract
209
   * Agent](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured#enhanced-extract-agent).
210
   *
211
   * <p>For information about supported file formats and languages, see the [Extract metadata from
212
   * file
213
   * (structured)](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured)
214
   * API guide.
215
   *
216
   * @param requestBody Request body of createAiExtractStructured method
217
   */
218
  public AiExtractStructuredResponse createAiExtractStructured(AiExtractStructured requestBody) {
219
    return createAiExtractStructured(requestBody, new CreateAiExtractStructuredHeaders());
×
220
  }
221

222
  /**
223
   * Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as
224
   * a set of key-value pairs.
225
   *
226
   * <p>To define the extraction structure, provide either a metadata template or a list of fields.
227
   * To learn more about creating templates, see [Creating metadata templates in the Admin
228
   * Console](https://support.box.com/hc/en-us/articles/360044194033-Customizing-Metadata-Templates)
229
   * or use the [metadata template API](https://developer.box.com/guides/metadata/templates/create).
230
   *
231
   * <p>This endpoint also supports [Enhanced Extract
232
   * Agent](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured#enhanced-extract-agent).
233
   *
234
   * <p>For information about supported file formats and languages, see the [Extract metadata from
235
   * file
236
   * (structured)](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured)
237
   * API guide.
238
   *
239
   * @param requestBody Request body of createAiExtractStructured method
240
   * @param headers Headers of createAiExtractStructured method
241
   */
242
  public AiExtractStructuredResponse createAiExtractStructured(
243
      AiExtractStructured requestBody, CreateAiExtractStructuredHeaders headers) {
244
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
×
245
    FetchResponse response =
×
246
        this.networkSession
247
            .getNetworkClient()
×
248
            .fetch(
×
249
                new FetchOptions.Builder(
250
                        String.join(
×
251
                            "",
252
                            this.networkSession.getBaseUrls().getBaseUrl(),
×
253
                            "/2.0/ai/extract_structured"),
254
                        "POST")
255
                    .headers(headersMap)
×
256
                    .data(JsonManager.serialize(requestBody))
×
257
                    .contentType("application/json")
×
258
                    .responseFormat(ResponseFormat.JSON)
×
259
                    .auth(this.auth)
×
260
                    .networkSession(this.networkSession)
×
261
                    .build());
×
262
    return JsonManager.deserialize(response.getData(), AiExtractStructuredResponse.class);
×
263
  }
264

265
  public Authentication getAuth() {
266
    return auth;
×
267
  }
268

269
  public NetworkSession getNetworkSession() {
270
    return networkSession;
×
271
  }
272

273
  public static class Builder {
274

275
    protected Authentication auth;
276

277
    protected NetworkSession networkSession;
278

NEW
279
    public Builder() {}
×
280

281
    public Builder auth(Authentication auth) {
UNCOV
282
      this.auth = auth;
×
UNCOV
283
      return this;
×
284
    }
285

286
    public Builder networkSession(NetworkSession networkSession) {
UNCOV
287
      this.networkSession = networkSession;
×
UNCOV
288
      return this;
×
289
    }
290

291
    public AiManager build() {
NEW
292
      if (this.networkSession == null) {
×
NEW
293
        this.networkSession = new NetworkSession();
×
294
      }
295
      return new AiManager(this);
×
296
    }
297
  }
298
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc