Skip to content

Commit 0ec40d4

Browse files
feat: Support AI Agent API (box/box-codegen#531) (#260)
1 parent fa8952a commit 0ec40d4

17 files changed

+1582
-177
lines changed

.codegen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "6a7e147", "specHash": "137da0d", "version": "1.2.0" }
1+
{ "engineHash": "f6b5758", "specHash": "d36b9f0", "version": "1.2.0" }

docs/ai.md

+35
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [Send AI question request](#send-ai-question-request)
44
- [Send AI request to generate text](#send-ai-request-to-generate-text)
5+
- [Get AI agent default configuration](#get-ai-agent-default-configuration)
56

67
## Send AI question request
78

@@ -95,3 +96,37 @@ await client.ai.createAiTextGen({
9596
This function returns a value of type `AiResponse`.
9697

9798
A successful response including the answer from the LLM.
99+
100+
## Get AI agent default configuration
101+
102+
Get the AI agent default config
103+
104+
This operation is performed by calling function `getAiAgentDefaultConfig`.
105+
106+
See the endpoint docs at
107+
[API Reference](https://developer.box.com/reference/get-ai-agent-default/).
108+
109+
<!-- sample get_ai_agent_default -->
110+
111+
```ts
112+
await client.ai.getAiAgentDefaultConfig({
113+
mode: 'text_gen' as GetAiAgentDefaultConfigQueryParamsModeField,
114+
language: 'en-US',
115+
} satisfies GetAiAgentDefaultConfigQueryParams);
116+
```
117+
118+
### Arguments
119+
120+
- queryParams `GetAiAgentDefaultConfigQueryParams`
121+
- Query parameters of getAiAgentDefaultConfig method
122+
- optionalsInput `GetAiAgentDefaultConfigOptionalsInput`
123+
-
124+
125+
### Returns
126+
127+
This function returns a value of type `AiAgentAskOrAiAgentTextGen`.
128+
129+
A successful response including the default agent configuration.
130+
This response can be one of the following two objects:
131+
AI agent for questions and AI agent for text generation. The response
132+
depends on the agent configuration requested in this endpoint.

package-lock.json

+174-174
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/managers/ai.generated.ts

+116-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ import { serializeAiAsk } from '../schemas/aiAsk.generated.js';
66
import { deserializeAiAsk } from '../schemas/aiAsk.generated.js';
77
import { serializeAiTextGen } from '../schemas/aiTextGen.generated.js';
88
import { deserializeAiTextGen } from '../schemas/aiTextGen.generated.js';
9+
import { serializeAiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js';
10+
import { deserializeAiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js';
911
import { AiResponse } from '../schemas/aiResponse.generated.js';
1012
import { ClientError } from '../schemas/clientError.generated.js';
1113
import { AiAsk } from '../schemas/aiAsk.generated.js';
1214
import { AiTextGen } from '../schemas/aiTextGen.generated.js';
15+
import { AiAgentAskOrAiAgentTextGen } from '../schemas/aiAgentAskOrAiAgentTextGen.generated.js';
1316
import { Authentication } from '../networking/auth.generated.js';
1417
import { NetworkSession } from '../networking/network.generated.js';
1518
import { prepareParams } from '../internal/utils.js';
@@ -20,6 +23,8 @@ import { FetchOptions } from '../networking/fetch.js';
2023
import { FetchResponse } from '../networking/fetch.js';
2124
import { fetch } from '../networking/fetch.js';
2225
import { SerializedData } from '../serialization/json.js';
26+
import { sdToJson } from '../serialization/json.js';
27+
import { BoxSdkError } from '../box/errors.js';
2328
import { sdIsEmpty } from '../serialization/json.js';
2429
import { sdIsBoolean } from '../serialization/json.js';
2530
import { sdIsNumber } from '../serialization/json.js';
@@ -64,6 +69,31 @@ export interface CreateAiTextGenOptionalsInput {
6469
readonly headers?: CreateAiTextGenHeaders;
6570
readonly cancellationToken?: undefined | CancellationToken;
6671
}
72+
export class GetAiAgentDefaultConfigOptionals {
73+
readonly headers: GetAiAgentDefaultConfigHeaders =
74+
new GetAiAgentDefaultConfigHeaders({});
75+
readonly cancellationToken?: CancellationToken = void 0;
76+
constructor(
77+
fields: Omit<
78+
GetAiAgentDefaultConfigOptionals,
79+
'headers' | 'cancellationToken'
80+
> &
81+
Partial<
82+
Pick<GetAiAgentDefaultConfigOptionals, 'headers' | 'cancellationToken'>
83+
>
84+
) {
85+
if (fields.headers) {
86+
this.headers = fields.headers;
87+
}
88+
if (fields.cancellationToken) {
89+
this.cancellationToken = fields.cancellationToken;
90+
}
91+
}
92+
}
93+
export interface GetAiAgentDefaultConfigOptionalsInput {
94+
readonly headers?: GetAiAgentDefaultConfigHeaders;
95+
readonly cancellationToken?: undefined | CancellationToken;
96+
}
6797
export class CreateAiAskHeaders {
6898
readonly extraHeaders?: {
6999
readonly [key: string]: undefined | string;
@@ -104,13 +134,42 @@ export interface CreateAiTextGenHeadersInput {
104134
readonly [key: string]: undefined | string;
105135
};
106136
}
137+
export type GetAiAgentDefaultConfigQueryParamsModeField = 'ask' | 'text_gen';
138+
export interface GetAiAgentDefaultConfigQueryParams {
139+
readonly mode: GetAiAgentDefaultConfigQueryParamsModeField;
140+
readonly language?: string;
141+
readonly model?: string;
142+
}
143+
export class GetAiAgentDefaultConfigHeaders {
144+
readonly extraHeaders?: {
145+
readonly [key: string]: undefined | string;
146+
} = {};
147+
constructor(
148+
fields: Omit<GetAiAgentDefaultConfigHeaders, 'extraHeaders'> &
149+
Partial<Pick<GetAiAgentDefaultConfigHeaders, 'extraHeaders'>>
150+
) {
151+
if (fields.extraHeaders) {
152+
this.extraHeaders = fields.extraHeaders;
153+
}
154+
}
155+
}
156+
export interface GetAiAgentDefaultConfigHeadersInput {
157+
readonly extraHeaders?:
158+
| undefined
159+
| {
160+
readonly [key: string]: undefined | string;
161+
};
162+
}
107163
export class AiManager {
108164
readonly auth?: Authentication;
109165
readonly networkSession: NetworkSession = new NetworkSession({});
110166
constructor(
111167
fields: Omit<
112168
AiManager,
113-
'networkSession' | 'createAiAsk' | 'createAiTextGen'
169+
| 'networkSession'
170+
| 'createAiAsk'
171+
| 'createAiTextGen'
172+
| 'getAiAgentDefaultConfig'
114173
> &
115174
Partial<Pick<AiManager, 'networkSession'>>
116175
) {
@@ -180,8 +239,64 @@ export class AiManager {
180239
)) as FetchResponse;
181240
return deserializeAiResponse(response.data);
182241
}
242+
async getAiAgentDefaultConfig(
243+
queryParams: GetAiAgentDefaultConfigQueryParams,
244+
optionalsInput: GetAiAgentDefaultConfigOptionalsInput = {}
245+
): Promise<AiAgentAskOrAiAgentTextGen> {
246+
const optionals: GetAiAgentDefaultConfigOptionals =
247+
new GetAiAgentDefaultConfigOptionals({
248+
headers: optionalsInput.headers,
249+
cancellationToken: optionalsInput.cancellationToken,
250+
});
251+
const headers: any = optionals.headers;
252+
const cancellationToken: any = optionals.cancellationToken;
253+
const queryParamsMap: {
254+
readonly [key: string]: string;
255+
} = prepareParams({
256+
['mode']: toString(queryParams.mode) as string,
257+
['language']: toString(queryParams.language) as string,
258+
['model']: toString(queryParams.model) as string,
259+
});
260+
const headersMap: {
261+
readonly [key: string]: string;
262+
} = prepareParams({ ...{}, ...headers.extraHeaders });
263+
const response: FetchResponse = (await fetch(
264+
''.concat(
265+
this.networkSession.baseUrls.baseUrl,
266+
'/2.0/ai_agent_default'
267+
) as string,
268+
{
269+
method: 'GET',
270+
params: queryParamsMap,
271+
headers: headersMap,
272+
responseFormat: 'json',
273+
auth: this.auth,
274+
networkSession: this.networkSession,
275+
cancellationToken: cancellationToken,
276+
} satisfies FetchOptions
277+
)) as FetchResponse;
278+
return deserializeAiAgentAskOrAiAgentTextGen(response.data);
279+
}
183280
}
184281
export interface AiManagerInput {
185282
readonly auth?: Authentication;
186283
readonly networkSession?: NetworkSession;
187284
}
285+
export function serializeGetAiAgentDefaultConfigQueryParamsModeField(
286+
val: GetAiAgentDefaultConfigQueryParamsModeField
287+
): SerializedData {
288+
return val;
289+
}
290+
export function deserializeGetAiAgentDefaultConfigQueryParamsModeField(
291+
val: SerializedData
292+
): GetAiAgentDefaultConfigQueryParamsModeField {
293+
if (val == 'ask') {
294+
return val;
295+
}
296+
if (val == 'text_gen') {
297+
return val;
298+
}
299+
throw new BoxSdkError({
300+
message: "Can't deserialize GetAiAgentDefaultConfigQueryParamsModeField",
301+
});
302+
}

src/schemas/aiAgentAsk.generated.ts

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { serializeAiAgentLongTextTool } from './aiAgentLongTextTool.generated.js';
2+
import { deserializeAiAgentLongTextTool } from './aiAgentLongTextTool.generated.js';
3+
import { serializeAiAgentBasicTextToolAsk } from './aiAgentBasicTextToolAsk.generated.js';
4+
import { deserializeAiAgentBasicTextToolAsk } from './aiAgentBasicTextToolAsk.generated.js';
5+
import { AiAgentLongTextTool } from './aiAgentLongTextTool.generated.js';
6+
import { AiAgentBasicTextToolAsk } from './aiAgentBasicTextToolAsk.generated.js';
7+
import { BoxSdkError } from '../box/errors.js';
8+
import { SerializedData } from '../serialization/json.js';
9+
import { sdIsEmpty } from '../serialization/json.js';
10+
import { sdIsBoolean } from '../serialization/json.js';
11+
import { sdIsNumber } from '../serialization/json.js';
12+
import { sdIsString } from '../serialization/json.js';
13+
import { sdIsList } from '../serialization/json.js';
14+
import { sdIsMap } from '../serialization/json.js';
15+
export type AiAgentAskTypeField = 'ai_agent_ask';
16+
export interface AiAgentAsk {
17+
readonly type?: AiAgentAskTypeField;
18+
readonly longText?: AiAgentLongTextTool;
19+
readonly basicText?: AiAgentBasicTextToolAsk;
20+
readonly longTextMulti?: AiAgentLongTextTool;
21+
readonly basicTextMulti?: AiAgentBasicTextToolAsk;
22+
}
23+
export function serializeAiAgentAskTypeField(
24+
val: AiAgentAskTypeField
25+
): SerializedData {
26+
return val;
27+
}
28+
export function deserializeAiAgentAskTypeField(
29+
val: SerializedData
30+
): AiAgentAskTypeField {
31+
if (val == 'ai_agent_ask') {
32+
return val;
33+
}
34+
throw new BoxSdkError({ message: "Can't deserialize AiAgentAskTypeField" });
35+
}
36+
export function serializeAiAgentAsk(val: AiAgentAsk): SerializedData {
37+
return {
38+
['type']:
39+
val.type == void 0 ? void 0 : serializeAiAgentAskTypeField(val.type),
40+
['long_text']:
41+
val.longText == void 0
42+
? void 0
43+
: serializeAiAgentLongTextTool(val.longText),
44+
['basic_text']:
45+
val.basicText == void 0
46+
? void 0
47+
: serializeAiAgentBasicTextToolAsk(val.basicText),
48+
['long_text_multi']:
49+
val.longTextMulti == void 0
50+
? void 0
51+
: serializeAiAgentLongTextTool(val.longTextMulti),
52+
['basic_text_multi']:
53+
val.basicTextMulti == void 0
54+
? void 0
55+
: serializeAiAgentBasicTextToolAsk(val.basicTextMulti),
56+
};
57+
}
58+
export function deserializeAiAgentAsk(val: SerializedData): AiAgentAsk {
59+
if (!sdIsMap(val)) {
60+
throw new BoxSdkError({ message: 'Expecting a map for "AiAgentAsk"' });
61+
}
62+
const type: undefined | AiAgentAskTypeField =
63+
val.type == void 0 ? void 0 : deserializeAiAgentAskTypeField(val.type);
64+
const longText: undefined | AiAgentLongTextTool =
65+
val.long_text == void 0
66+
? void 0
67+
: deserializeAiAgentLongTextTool(val.long_text);
68+
const basicText: undefined | AiAgentBasicTextToolAsk =
69+
val.basic_text == void 0
70+
? void 0
71+
: deserializeAiAgentBasicTextToolAsk(val.basic_text);
72+
const longTextMulti: undefined | AiAgentLongTextTool =
73+
val.long_text_multi == void 0
74+
? void 0
75+
: deserializeAiAgentLongTextTool(val.long_text_multi);
76+
const basicTextMulti: undefined | AiAgentBasicTextToolAsk =
77+
val.basic_text_multi == void 0
78+
? void 0
79+
: deserializeAiAgentBasicTextToolAsk(val.basic_text_multi);
80+
return {
81+
type: type,
82+
longText: longText,
83+
basicText: basicText,
84+
longTextMulti: longTextMulti,
85+
basicTextMulti: basicTextMulti,
86+
} satisfies AiAgentAsk;
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { serializeAiAgentAsk } from './aiAgentAsk.generated.js';
2+
import { deserializeAiAgentAsk } from './aiAgentAsk.generated.js';
3+
import { serializeAiAgentTextGen } from './aiAgentTextGen.generated.js';
4+
import { deserializeAiAgentTextGen } from './aiAgentTextGen.generated.js';
5+
import { AiAgentAsk } from './aiAgentAsk.generated.js';
6+
import { AiAgentTextGen } from './aiAgentTextGen.generated.js';
7+
import { BoxSdkError } from '../box/errors.js';
8+
import { SerializedData } from '../serialization/json.js';
9+
import { sdIsEmpty } from '../serialization/json.js';
10+
import { sdIsBoolean } from '../serialization/json.js';
11+
import { sdIsNumber } from '../serialization/json.js';
12+
import { sdIsString } from '../serialization/json.js';
13+
import { sdIsList } from '../serialization/json.js';
14+
import { sdIsMap } from '../serialization/json.js';
15+
export type AiAgentAskOrAiAgentTextGen = AiAgentAsk | AiAgentTextGen;
16+
export function serializeAiAgentAskOrAiAgentTextGen(val: any): SerializedData {
17+
if (val.type == 'ai_agent_ask') {
18+
return serializeAiAgentAsk(val);
19+
}
20+
if (val.type == 'ai_agent_text_gen') {
21+
return serializeAiAgentTextGen(val);
22+
}
23+
throw new BoxSdkError({ message: 'unknown type' });
24+
}
25+
export function deserializeAiAgentAskOrAiAgentTextGen(
26+
val: SerializedData
27+
): AiAgentAskOrAiAgentTextGen {
28+
if (!sdIsMap(val)) {
29+
throw new BoxSdkError({
30+
message: 'Expecting a map for "AiAgentAskOrAiAgentTextGen"',
31+
});
32+
}
33+
if (val.type == 'ai_agent_ask') {
34+
return deserializeAiAgentAsk(val);
35+
}
36+
if (val.type == 'ai_agent_text_gen') {
37+
return deserializeAiAgentTextGen(val);
38+
}
39+
throw new BoxSdkError({
40+
message: "Can't deserialize AiAgentAskOrAiAgentTextGen",
41+
});
42+
}

0 commit comments

Comments
 (0)