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

box / box-java-sdk / #4027

11 Oct 2024 12:22PM UTC coverage: 71.745% (+0.04%) from 71.703%
#4027

push

github

web-flow
feat: Support AI extract and AI extract structured (#1266)

125 of 167 new or added lines in 8 files covered. (74.85%)

1 existing line in 1 file now uncovered.

8039 of 11205 relevant lines covered (71.74%)

0.72 hits per line

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

58.7
/src/main/java/com/box/sdk/BoxAIAgent.java
1
package com.box.sdk;
2

3
import com.eclipsesource.json.JsonObject;
4
import com.eclipsesource.json.JsonValue;
5

6
public abstract class BoxAIAgent extends BoxJSONObject {
7
    /**
8
     * The type of the AI agent.
9
     * Value can be "ai_agent_ask" or "ai_agent_text_gen", "ai_agent_extract", "ai_agent_extract_structured".
10
     */
11
    private String type;
12

13
    /**
14
     * Constructs an AI agent with default settings.
15
     * @param type The type of the AI agent.
16
     *            Value can be "ai_agent_ask", "ai_agent_text_gen", "ai_agent_extract", "ai_agent_extract_structured".
17
     */
18
    public BoxAIAgent(String type) {
19
        super();
×
20
        this.type = type;
×
21
    }
×
22

23
    /**
24
     * Constructs an AI agent with default settings.
25
     * @param jsonObject JSON object representing the AI agent.
26
     */
27
    public BoxAIAgent(JsonObject jsonObject) {
28
        super(jsonObject);
1✔
29
    }
1✔
30

31
    /**
32
     * Constructs an AI agent with default settings.
33
     * @param jsonObject JSON object representing the AI agent.
34
     */
35
    public static BoxAIAgent parse(JsonObject jsonObject) {
36
        String type = jsonObject.get("type").asString();
1✔
37
        if (type.equals(BoxAIAgentAsk.TYPE)) {
1✔
38
            return new BoxAIAgentAsk(jsonObject);
1✔
39
        } else if (type.equals(BoxAIAgentTextGen.TYPE)) {
1✔
40
            return new BoxAIAgentTextGen(jsonObject);
1✔
41
        } else if (type.equals(BoxAIAgentExtract.TYPE)) {
1✔
42
            return new BoxAIAgentExtract(jsonObject);
1✔
43
        } else if (type.equals(BoxAIAgentExtractStructured.TYPE)) {
1✔
44
            return new BoxAIAgentExtractStructured(jsonObject);
1✔
45
        } else {
46
            throw new IllegalArgumentException("Invalid AI agent type: " + type);
×
47
        }
48
    }
49

50
    /**
51
     * Gets the type of the AI agent.
52
     * @return The type of the AI agent.
53
     */
54
    public String getType() {
55
        return type;
1✔
56
    }
57

58
    /**
59
     * Sets the type of the AI agent.
60
     * @param type The type of the AI agent.
61
     */
62
    public void setType(String type) {
63
        this.type = type;
×
64
    }
×
65

66
    @Override
67
    void parseJSONMember(JsonObject.Member member) {
68
        super.parseJSONMember(member);
1✔
69
        String memberName = member.getName();
1✔
70
        JsonValue value = member.getValue();
1✔
71
        if (memberName.equals("type")) {
1✔
72
            this.type = value.asString();
1✔
73
        }
74
    }
1✔
75

76
    public JsonObject getJSONObject() {
77
        JsonObject jsonObject = new JsonObject();
×
78
        jsonObject.add("type", this.type);
×
79
        return jsonObject;
×
80
    }
81

82
    /**
83
     * The type of the AI agent for asking questions.
84
     */
85
    public enum Mode {
1✔
86
        /**
87
         * The type of AI agent used to handle queries.
88
         */
89
        ASK("ask"),
1✔
90
        /**
91
         * The type of AI agent used for generating text.
92
         */
93
        TEXT_GEN("text_gen"),
1✔
94
        /**
95
         * The type of AI agent used for extracting metadata freeform.
96
         */
97
        EXTRACT("extract"),
1✔
98
        /**
99
         * The type of AI agent used for extracting metadata structured.
100
         */
101
        EXTRACT_STRUCTURED("extract_structured");
1✔
102

103

104
        private final String value;
105

106
        Mode(String value) {
1✔
107
            this.value = value;
1✔
108
        }
1✔
109

110
        static BoxAIAgent.Mode fromJSONValue(String value) {
111
            if (value.equals("ask")) {
×
112
                return ASK;
×
113
            } else if (value.equals("text_gen")) {
×
114
                return TEXT_GEN;
×
NEW
115
            } else if (value.equals("extract")) {
×
NEW
116
                return EXTRACT;
×
NEW
117
            } else if (value.equals("extract_structured")) {
×
NEW
118
                return EXTRACT_STRUCTURED;
×
119
            } else {
120
                throw new IllegalArgumentException("Invalid AI agent mode: " + value);
×
121
            }
122
        }
123

124
        String toJSONValue() {
125
            return this.value;
×
126
        }
127

128
        @Override
129
        public String toString() {
130
            return this.value;
1✔
131
        }
132
    }
133
}
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