box-node-sdk
Version:
Official SDK for Box Platform APIs
125 lines (124 loc) • 4.16 kB
text/typescript
import { BoxSdkError } from '../box/errors';
import { SerializedData } from '../serialization/json';
import { sdIsEmpty } from '../serialization/json';
import { sdIsBoolean } from '../serialization/json';
import { sdIsNumber } from '../serialization/json';
import { sdIsString } from '../serialization/json';
import { sdIsList } from '../serialization/json';
import { sdIsMap } from '../serialization/json';
export type AiAgentReferenceTypeField = 'ai_agent_id';
export class AiAgentReference {
/**
* The type of AI agent used to handle queries. */
readonly type: AiAgentReferenceTypeField =
'ai_agent_id' as AiAgentReferenceTypeField;
/**
* The ID of an Agent. This can be a numeric ID for custom agents (for example, `14031`)
* or a unique identifier for pre-built agents (for example, `enhanced_extract_agent`
* for the [Enhanced Extract Agent](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured#enhanced-extract-agent)). */
readonly id?: string;
readonly rawData?: SerializedData;
constructor(
fields: Omit<AiAgentReference, 'type'> &
Partial<Pick<AiAgentReference, 'type'>>,
) {
if (fields.type !== undefined) {
this.type = fields.type;
}
if (fields.id !== undefined) {
this.id = fields.id;
}
if (fields.rawData !== undefined) {
this.rawData = fields.rawData;
}
}
}
export interface AiAgentReferenceInput {
/**
* The type of AI agent used to handle queries. */
readonly type?: AiAgentReferenceTypeField;
/**
* The ID of an Agent. This can be a numeric ID for custom agents (for example, `14031`)
* or a unique identifier for pre-built agents (for example, `enhanced_extract_agent`
* for the [Enhanced Extract Agent](https://developer.box.com/guides/box-ai/ai-tutorials/extract-metadata-structured#enhanced-extract-agent)). */
readonly id?: string;
readonly rawData?: SerializedData;
}
export function serializeAiAgentReferenceTypeField(
val: AiAgentReferenceTypeField,
): SerializedData {
return val;
}
export function deserializeAiAgentReferenceTypeField(
val: SerializedData,
): AiAgentReferenceTypeField {
if (val == 'ai_agent_id') {
return val;
}
throw new BoxSdkError({
message: "Can't deserialize AiAgentReferenceTypeField",
});
}
export function serializeAiAgentReference(
val: AiAgentReference,
): SerializedData {
return {
['type']: serializeAiAgentReferenceTypeField(val.type),
['id']: val.id,
};
}
export function deserializeAiAgentReference(
val: SerializedData,
): AiAgentReference {
if (!sdIsMap(val)) {
throw new BoxSdkError({
message: 'Expecting a map for "AiAgentReference"',
});
}
if (val.type == void 0) {
throw new BoxSdkError({
message: 'Expecting "type" of type "AiAgentReference" to be defined',
});
}
const type: AiAgentReferenceTypeField = deserializeAiAgentReferenceTypeField(
val.type,
);
if (!(val.id == void 0) && !sdIsString(val.id)) {
throw new BoxSdkError({
message: 'Expecting string for "id" of type "AiAgentReference"',
});
}
const id: undefined | string = val.id == void 0 ? void 0 : val.id;
return { type: type, id: id } satisfies AiAgentReference;
}
export function serializeAiAgentReferenceInput(
val: AiAgentReferenceInput,
): SerializedData {
return {
['type']:
val.type == void 0
? val.type
: serializeAiAgentReferenceTypeField(val.type),
['id']: val.id,
};
}
export function deserializeAiAgentReferenceInput(
val: SerializedData,
): AiAgentReferenceInput {
if (!sdIsMap(val)) {
throw new BoxSdkError({
message: 'Expecting a map for "AiAgentReferenceInput"',
});
}
const type: undefined | AiAgentReferenceTypeField =
val.type == void 0
? void 0
: deserializeAiAgentReferenceTypeField(val.type);
if (!(val.id == void 0) && !sdIsString(val.id)) {
throw new BoxSdkError({
message: 'Expecting string for "id" of type "AiAgentReferenceInput"',
});
}
const id: undefined | string = val.id == void 0 ? void 0 : val.id;
return { type: type, id: id } satisfies AiAgentReferenceInput;
}