Skip to content

Commit f0d0196

Browse files
box-sdk-buildbox-sdk-build
andauthored
feat: Add new parameters to ai extract structured method (box/box-openapi#604) (#1512)
Co-authored-by: box-sdk-build <box-sdk-build@box.com>
1 parent 968c5cb commit f0d0196

12 files changed

Lines changed: 547 additions & 15 deletions

‎.codegen.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "a87c352", "specHash": "ded99bf", "version": "10.11.1" }
1+
{ "engineHash": "a87c352", "specHash": "0ac3d31", "version": "10.11.1" }

‎docs/userCollaborations.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ group IDs.
106106
If a collaboration is being created with a group, access to
107107
this endpoint is dependent on the group's ability to be invited.
108108

109-
If collaboration is in `pending` status, the following fields
110-
are redacted:
109+
If collaboration is in `pending` status, field `name` is redacted when:
111110

112-
- `login` and `name` are hidden if a collaboration was created
113-
using `user_id`,
114-
- `name` is hidden if a collaboration was created using `login`.
111+
- a collaboration was created using `user_id`,
112+
- a collaboration was created using `login`.
115113

116114
This operation is performed by calling function `createCollaboration`.
117115

‎src/managers/userCollaborations.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,9 @@ export class UserCollaborationsManager {
592592
* If a collaboration is being created with a group, access to
593593
* this endpoint is dependent on the group's ability to be invited.
594594
*
595-
* If collaboration is in `pending` status, the following fields
596-
* are redacted:
597-
* - `login` and `name` are hidden if a collaboration was created
598-
* using `user_id`,
599-
* - `name` is hidden if a collaboration was created using `login`.
595+
* If collaboration is in `pending` status, field `name` is redacted when:
596+
* - a collaboration was created using `user_id`,
597+
* - a collaboration was created using `login`.
600598
* @param {CreateCollaborationRequestBody} requestBody Request body of createCollaboration method
601599
* @param {CreateCollaborationOptionalsInput} optionalsInput
602600
* @returns {Promise<Collaboration>}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { BoxSdkError } from '../box/errors';
2+
import { SerializedData } from '../serialization/json';
3+
import { sdIsEmpty } from '../serialization/json';
4+
import { sdIsBoolean } from '../serialization/json';
5+
import { sdIsNumber } from '../serialization/json';
6+
import { sdIsString } from '../serialization/json';
7+
import { sdIsList } from '../serialization/json';
8+
import { sdIsMap } from '../serialization/json';
9+
export interface AiExtractFieldOption {
10+
/**
11+
* A unique identifier for the option. */
12+
readonly key: string;
13+
readonly rawData?: SerializedData;
14+
}
15+
export function serializeAiExtractFieldOption(
16+
val: AiExtractFieldOption,
17+
): SerializedData {
18+
return { ['key']: val.key };
19+
}
20+
export function deserializeAiExtractFieldOption(
21+
val: SerializedData,
22+
): AiExtractFieldOption {
23+
if (!sdIsMap(val)) {
24+
throw new BoxSdkError({
25+
message: 'Expecting a map for "AiExtractFieldOption"',
26+
});
27+
}
28+
if (val.key == void 0) {
29+
throw new BoxSdkError({
30+
message: 'Expecting "key" of type "AiExtractFieldOption" to be defined',
31+
});
32+
}
33+
if (!sdIsString(val.key)) {
34+
throw new BoxSdkError({
35+
message: 'Expecting string for "key" of type "AiExtractFieldOption"',
36+
});
37+
}
38+
const key: string = val.key;
39+
return { key: key } satisfies AiExtractFieldOption;
40+
}

‎src/schemas/aiExtractStructured.ts‎

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@ import { serializeAiAgentReference } from './aiAgentReference';
22
import { deserializeAiAgentReference } from './aiAgentReference';
33
import { serializeAiAgentExtractStructured } from './aiAgentExtractStructured';
44
import { deserializeAiAgentExtractStructured } from './aiAgentExtractStructured';
5+
import { serializeAiTaxonomyReference } from './aiTaxonomyReference';
6+
import { deserializeAiTaxonomyReference } from './aiTaxonomyReference';
7+
import { serializeAiTaxonomyFileReference } from './aiTaxonomyFileReference';
8+
import { deserializeAiTaxonomyFileReference } from './aiTaxonomyFileReference';
59
import { serializeAiItemBase } from './aiItemBase';
610
import { deserializeAiItemBase } from './aiItemBase';
11+
import { serializeAiExtractSubField } from './aiExtractSubField';
12+
import { deserializeAiExtractSubField } from './aiExtractSubField';
13+
import { serializeAiOptionsRules } from './aiOptionsRules';
14+
import { deserializeAiOptionsRules } from './aiOptionsRules';
715
import { serializeAiExtractStructuredAgent } from './aiExtractStructuredAgent';
816
import { deserializeAiExtractStructuredAgent } from './aiExtractStructuredAgent';
17+
import { serializeAiTaxonomySource } from './aiTaxonomySource';
18+
import { deserializeAiTaxonomySource } from './aiTaxonomySource';
919
import { AiAgentReference } from './aiAgentReference';
1020
import { AiAgentExtractStructured } from './aiAgentExtractStructured';
21+
import { AiTaxonomyReference } from './aiTaxonomyReference';
22+
import { AiTaxonomyFileReference } from './aiTaxonomyFileReference';
1123
import { AiItemBase } from './aiItemBase';
24+
import { AiExtractSubField } from './aiExtractSubField';
25+
import { AiOptionsRules } from './aiOptionsRules';
1226
import { AiExtractStructuredAgent } from './aiExtractStructuredAgent';
27+
import { AiTaxonomySource } from './aiTaxonomySource';
1328
import { BoxSdkError } from '../box/errors';
1429
import { SerializedData } from '../serialization/json';
1530
import { sdIsEmpty } from '../serialization/json';
@@ -56,11 +71,21 @@ export interface AiExtractStructuredFieldsField {
5671
* The context about the key that may include how to find and format it. */
5772
readonly prompt?: string;
5873
/**
59-
* The type of the field. It can include but is not limited to `string`, `float`, `date`, `enum`, and `multiSelect`. */
74+
* The type of the field. It can include but is not limited to `string`, `float`, `date`, `enum`, `multiSelect`,`taxonomy`, `struct`, and `table`. */
6075
readonly type?: string;
6176
/**
6277
* A list of options for this field. This is most often used in combination with the `enum` and `multiSelect` field types. */
6378
readonly options?: readonly AiExtractStructuredFieldsOptionsField[];
79+
/**
80+
* The nested fields for this field. Used with `struct` and `table` field types to define the nested structure. */
81+
readonly fields?: readonly AiExtractSubField[];
82+
/**
83+
* The identifier for a taxonomy, which corresponds to the `key` of the taxonomy source. Required if using `taxonomy` type field. */
84+
readonly taxonomyKey?: string;
85+
/**
86+
* The namespace of the taxonomy source. Required if using `taxonomy` type field from an existing taxonomy. */
87+
readonly namespace?: string;
88+
readonly optionsRules?: AiOptionsRules;
6489
readonly rawData?: SerializedData;
6590
}
6691
export interface AiExtractStructured {
@@ -82,6 +107,10 @@ export interface AiExtractStructured {
82107
/**
83108
* A flag to indicate whether references for every extracted field should be returned. */
84109
readonly includeReference?: boolean;
110+
/**
111+
* The taxonomy sources to be used for the structured extraction. They can either be an existing file or a taxonomy.
112+
* For your request to work, `fields` must also be provided. `taxonomy_sources` is not supported with `metadata_template`. */
113+
readonly taxonomySources?: readonly AiTaxonomySource[];
85114
readonly rawData?: SerializedData;
86115
}
87116
export function serializeAiExtractStructuredMetadataTemplateTypeField(
@@ -189,6 +218,18 @@ export function serializeAiExtractStructuredFieldsField(
189218
): SerializedData {
190219
return serializeAiExtractStructuredFieldsOptionsField(item);
191220
}) as readonly any[]),
221+
['fields']:
222+
val.fields == void 0
223+
? val.fields
224+
: (val.fields.map(function (item: AiExtractSubField): SerializedData {
225+
return serializeAiExtractSubField(item);
226+
}) as readonly any[]),
227+
['taxonomy_key']: val.taxonomyKey,
228+
['namespace']: val.namespace,
229+
['options_rules']:
230+
val.optionsRules == void 0
231+
? val.optionsRules
232+
: serializeAiOptionsRules(val.optionsRules),
192233
};
193234
}
194235
export function deserializeAiExtractStructuredFieldsField(
@@ -258,13 +299,51 @@ export function deserializeAiExtractStructuredFieldsField(
258299
return deserializeAiExtractStructuredFieldsOptionsField(itm);
259300
}) as readonly any[])
260301
: [];
302+
if (!(val.fields == void 0) && !sdIsList(val.fields)) {
303+
throw new BoxSdkError({
304+
message:
305+
'Expecting array for "fields" of type "AiExtractStructuredFieldsField"',
306+
});
307+
}
308+
const fields: undefined | readonly AiExtractSubField[] =
309+
val.fields == void 0
310+
? void 0
311+
: sdIsList(val.fields)
312+
? (val.fields.map(function (itm: SerializedData): AiExtractSubField {
313+
return deserializeAiExtractSubField(itm);
314+
}) as readonly any[])
315+
: [];
316+
if (!(val.taxonomy_key == void 0) && !sdIsString(val.taxonomy_key)) {
317+
throw new BoxSdkError({
318+
message:
319+
'Expecting string for "taxonomy_key" of type "AiExtractStructuredFieldsField"',
320+
});
321+
}
322+
const taxonomyKey: undefined | string =
323+
val.taxonomy_key == void 0 ? void 0 : val.taxonomy_key;
324+
if (!(val.namespace == void 0) && !sdIsString(val.namespace)) {
325+
throw new BoxSdkError({
326+
message:
327+
'Expecting string for "namespace" of type "AiExtractStructuredFieldsField"',
328+
});
329+
}
330+
const namespace: undefined | string =
331+
val.namespace == void 0 ? void 0 : val.namespace;
332+
const optionsRules: undefined | AiOptionsRules =
333+
val.options_rules == void 0
334+
? void 0
335+
: deserializeAiOptionsRules(val.options_rules);
261336
return {
262337
key: key,
263338
description: description,
264339
displayName: displayName,
265340
prompt: prompt,
266341
type: type,
267342
options: options,
343+
fields: fields,
344+
taxonomyKey: taxonomyKey,
345+
namespace: namespace,
346+
optionsRules: optionsRules,
268347
} satisfies AiExtractStructuredFieldsField;
269348
}
270349
export function serializeAiExtractStructured(
@@ -294,6 +373,14 @@ export function serializeAiExtractStructured(
294373
: serializeAiExtractStructuredAgent(val.aiAgent),
295374
['include_confidence_score']: val.includeConfidenceScore,
296375
['include_reference']: val.includeReference,
376+
['taxonomy_sources']:
377+
val.taxonomySources == void 0
378+
? val.taxonomySources
379+
: (val.taxonomySources.map(function (
380+
item: AiTaxonomySource,
381+
): SerializedData {
382+
return serializeAiTaxonomySource(item);
383+
}) as readonly any[]),
297384
};
298385
}
299386
export function deserializeAiExtractStructured(
@@ -368,12 +455,29 @@ export function deserializeAiExtractStructured(
368455
}
369456
const includeReference: undefined | boolean =
370457
val.include_reference == void 0 ? void 0 : val.include_reference;
458+
if (!(val.taxonomy_sources == void 0) && !sdIsList(val.taxonomy_sources)) {
459+
throw new BoxSdkError({
460+
message:
461+
'Expecting array for "taxonomy_sources" of type "AiExtractStructured"',
462+
});
463+
}
464+
const taxonomySources: undefined | readonly AiTaxonomySource[] =
465+
val.taxonomy_sources == void 0
466+
? void 0
467+
: sdIsList(val.taxonomy_sources)
468+
? (val.taxonomy_sources.map(function (
469+
itm: SerializedData,
470+
): AiTaxonomySource {
471+
return deserializeAiTaxonomySource(itm);
472+
}) as readonly any[])
473+
: [];
371474
return {
372475
items: items,
373476
metadataTemplate: metadataTemplate,
374477
fields: fields,
375478
aiAgent: aiAgent,
376479
includeConfidenceScore: includeConfidenceScore,
377480
includeReference: includeReference,
481+
taxonomySources: taxonomySources,
378482
} satisfies AiExtractStructured;
379483
}

‎src/schemas/aiExtractSubField.ts‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { serializeAiExtractFieldOption } from './aiExtractFieldOption';
2+
import { deserializeAiExtractFieldOption } from './aiExtractFieldOption';
3+
import { AiExtractFieldOption } from './aiExtractFieldOption';
4+
import { BoxSdkError } from '../box/errors';
5+
import { SerializedData } from '../serialization/json';
6+
import { sdIsEmpty } from '../serialization/json';
7+
import { sdIsBoolean } from '../serialization/json';
8+
import { sdIsNumber } from '../serialization/json';
9+
import { sdIsString } from '../serialization/json';
10+
import { sdIsList } from '../serialization/json';
11+
import { sdIsMap } from '../serialization/json';
12+
export interface AiExtractSubField {
13+
/**
14+
* A unique identifier for the nested field. */
15+
readonly key: string;
16+
/**
17+
* A description of the nested field. */
18+
readonly description?: string;
19+
/**
20+
* The display name of the nested field. */
21+
readonly displayName?: string;
22+
/**
23+
* Context about the nested field that may include how to find and how to format it. */
24+
readonly prompt?: string;
25+
/**
26+
* The type of the nested field. Allowed types include `string`, `float`, `date`, `number`, `text`, `boolean`, `enum` and `multiSelect`. */
27+
readonly type?: string;
28+
/**
29+
* A list of options for this nested field. Used with `enum` and `multiSelect` types. */
30+
readonly options?: readonly AiExtractFieldOption[];
31+
readonly rawData?: SerializedData;
32+
}
33+
export function serializeAiExtractSubField(
34+
val: AiExtractSubField,
35+
): SerializedData {
36+
return {
37+
['key']: val.key,
38+
['description']: val.description,
39+
['displayName']: val.displayName,
40+
['prompt']: val.prompt,
41+
['type']: val.type,
42+
['options']:
43+
val.options == void 0
44+
? val.options
45+
: (val.options.map(function (
46+
item: AiExtractFieldOption,
47+
): SerializedData {
48+
return serializeAiExtractFieldOption(item);
49+
}) as readonly any[]),
50+
};
51+
}
52+
export function deserializeAiExtractSubField(
53+
val: SerializedData,
54+
): AiExtractSubField {
55+
if (!sdIsMap(val)) {
56+
throw new BoxSdkError({
57+
message: 'Expecting a map for "AiExtractSubField"',
58+
});
59+
}
60+
if (val.key == void 0) {
61+
throw new BoxSdkError({
62+
message: 'Expecting "key" of type "AiExtractSubField" to be defined',
63+
});
64+
}
65+
if (!sdIsString(val.key)) {
66+
throw new BoxSdkError({
67+
message: 'Expecting string for "key" of type "AiExtractSubField"',
68+
});
69+
}
70+
const key: string = val.key;
71+
if (!(val.description == void 0) && !sdIsString(val.description)) {
72+
throw new BoxSdkError({
73+
message: 'Expecting string for "description" of type "AiExtractSubField"',
74+
});
75+
}
76+
const description: undefined | string =
77+
val.description == void 0 ? void 0 : val.description;
78+
if (!(val.displayName == void 0) && !sdIsString(val.displayName)) {
79+
throw new BoxSdkError({
80+
message: 'Expecting string for "displayName" of type "AiExtractSubField"',
81+
});
82+
}
83+
const displayName: undefined | string =
84+
val.displayName == void 0 ? void 0 : val.displayName;
85+
if (!(val.prompt == void 0) && !sdIsString(val.prompt)) {
86+
throw new BoxSdkError({
87+
message: 'Expecting string for "prompt" of type "AiExtractSubField"',
88+
});
89+
}
90+
const prompt: undefined | string = val.prompt == void 0 ? void 0 : val.prompt;
91+
if (!(val.type == void 0) && !sdIsString(val.type)) {
92+
throw new BoxSdkError({
93+
message: 'Expecting string for "type" of type "AiExtractSubField"',
94+
});
95+
}
96+
const type: undefined | string = val.type == void 0 ? void 0 : val.type;
97+
if (!(val.options == void 0) && !sdIsList(val.options)) {
98+
throw new BoxSdkError({
99+
message: 'Expecting array for "options" of type "AiExtractSubField"',
100+
});
101+
}
102+
const options: undefined | readonly AiExtractFieldOption[] =
103+
val.options == void 0
104+
? void 0
105+
: sdIsList(val.options)
106+
? (val.options.map(function (
107+
itm: SerializedData,
108+
): AiExtractFieldOption {
109+
return deserializeAiExtractFieldOption(itm);
110+
}) as readonly any[])
111+
: [];
112+
return {
113+
key: key,
114+
description: description,
115+
displayName: displayName,
116+
prompt: prompt,
117+
type: type,
118+
options: options,
119+
} satisfies AiExtractSubField;
120+
}

0 commit comments

Comments
 (0)