-
Notifications
You must be signed in to change notification settings - Fork 351
refactor(schemas): migrate API schemas from Flow to TypeScript #4802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bonchevskyi
wants to merge
1
commit into
box:master
Choose a base branch
from
bonchevskyi:refactor/flow-to-ts-schemas
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| import type { AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi } from './AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi'; | ||
|
|
||
| export interface AiAgentBasicTextTool { | ||
| /** | ||
| * The model to be used for the AI Agent for basic text. | ||
| */ | ||
| readonly model?: string; | ||
| /** | ||
| * System messages try to help the LLM "understand" its role and what it is supposed to do. | ||
| */ | ||
| readonly system_message?: string; | ||
| /** | ||
| * Prompt template containing contextual information and the user prompt. May include inputs for | ||
| * `{current_date}`, `{user_question}`, and `{content}` depending on the use. | ||
| */ | ||
| readonly prompt_template?: string; | ||
| /** | ||
| * The number of tokens for completion. | ||
| */ | ||
| readonly num_tokens_for_completion?: number; | ||
| /** | ||
| * The parameters for the selected LLM endpoint. | ||
| */ | ||
| readonly llm_endpoint_params?: AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi; | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| import type { AiAgentBasicTextTool } from './AiAgentBasicTextTool'; | ||
| import type { AiAgentLongTextTool } from './AiAgentLongTextTool'; | ||
|
|
||
| export type AiAgentExtractStructuredTypeField = 'ai_agent_extract_structured'; | ||
|
|
||
| export interface AiAgentExtractStructured { | ||
| /** | ||
| * The type of AI agent to be used for extraction. | ||
| */ | ||
| readonly type: AiAgentExtractStructuredTypeField; | ||
| /** | ||
| * The long-text tool configuration. | ||
| */ | ||
| readonly long_text?: AiAgentLongTextTool; | ||
| /** | ||
| * The basic-text tool configuration. | ||
| */ | ||
| readonly basic_text?: AiAgentBasicTextTool; | ||
| } | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| import type { AiAgentBasicTextTool } from './AiAgentBasicTextTool'; | ||
|
|
||
| export interface AiAgentLongTextToolEmbeddingsStrategyField { | ||
| /** | ||
| * The strategy to be used for the AI Agent for calculating embeddings. | ||
| */ | ||
| readonly id?: string; | ||
| /** | ||
| * The number of tokens per chunk. | ||
| */ | ||
| readonly num_tokens_per_chunk?: number; | ||
| } | ||
|
|
||
| export interface AiAgentLongTextToolEmbeddingsField { | ||
| /** | ||
| * The model to be used for the AI Agent for calculating embeddings. | ||
| */ | ||
| readonly model?: string; | ||
| /** | ||
| * The strategy configuration used to calculate embeddings. | ||
| */ | ||
| readonly strategy?: AiAgentLongTextToolEmbeddingsStrategyField; | ||
| } | ||
|
|
||
| export type AiAgentLongTextTool = AiAgentBasicTextTool & { | ||
| /** The embeddings configuration for long-text processing. */ | ||
| readonly embeddings?: AiAgentLongTextToolEmbeddingsField; | ||
| }; |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| export type AiAgentTypeField = 'ai_agent_id'; | ||
|
|
||
| export interface AiAgentReference { | ||
| /** | ||
| * AI Agent Reference type used to pass a custom AI Agent ID to requests. | ||
| * See https://developer.box.com/reference/resources/ai-agent-reference/ | ||
| */ | ||
| readonly type: AiAgentTypeField; | ||
| /** | ||
| * The ID of the custom AI Agent. | ||
| */ | ||
| readonly id: string; | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| export interface AiExtractConfidenceScore { | ||
| /** The qualitative confidence level. */ | ||
| level: string; | ||
| /** The numeric confidence score. */ | ||
| score: number; | ||
| } | ||
|
|
||
| export interface AiExtractReference { | ||
| /** The ID of the referenced item. */ | ||
| itemId: string; | ||
| /** The page containing the referenced text. */ | ||
| page: number; | ||
| /** The referenced text. */ | ||
| text: string; | ||
| /** The position of the referenced text on the page. */ | ||
| boundingBox?: { | ||
| left: number; | ||
| top: number; | ||
| right: number; | ||
| bottom: number; | ||
| }; | ||
| } | ||
|
|
||
| export interface AiAgentInfo { | ||
| /** The models used by the AI Agent. */ | ||
| models?: Array<{ | ||
| name?: string; | ||
| provider?: string; | ||
| supported_purpose?: string; | ||
| }>; | ||
| /** The processor used by the AI Agent. */ | ||
| processor?: string; | ||
| } | ||
|
|
||
| export interface AiExtractResponse { | ||
| /** The fields extracted from the supplied items. */ | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Preserve the Flow schema's arbitrary answer values | ||
| answer: { [key: string]: any }; | ||
| /** The date and time when the response was created. */ | ||
| created_at: string; | ||
| /** The reason the extraction was completed. */ | ||
| completion_reason?: string; | ||
| /** Confidence scores keyed by extracted field. */ | ||
| confidence_score?: { [key: string]: AiExtractConfidenceScore }; | ||
| /** References keyed by extracted field. */ | ||
| reference?: { [key: string]: Array<AiExtractReference> }; | ||
| /** Information about the AI Agent used for extraction. */ | ||
| ai_agent_info?: AiAgentInfo; | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| import type { AiAgentExtractStructured } from './AiAgentExtractStructured'; | ||
| import type { AiAgentReference } from './AiAgentReference'; | ||
| import type { AiItemBase } from './AiItemBase'; | ||
|
|
||
| export type AiExtractStructuredMetadataTemplateTypeField = 'metadata_template'; | ||
|
|
||
| export interface AiExtractStructuredMetadataTemplateField { | ||
| /** | ||
| * The name of the metadata template. | ||
| */ | ||
| readonly template_key?: string; | ||
| /** | ||
| * Value is always `metadata_template`. | ||
| */ | ||
| readonly type?: AiExtractStructuredMetadataTemplateTypeField; | ||
| /** | ||
| * The scope of the metadata template can either be global or enterprise_*. The global scope is used for | ||
| * templates that are available to any Box enterprise. The enterprise_* scope represents templates that have | ||
| * been created within a specific enterprise, where * is the ID of that enterprise. | ||
| */ | ||
| readonly scope?: string; | ||
| } | ||
|
|
||
| export interface AiExtractStructuredFieldsOptionsField { | ||
| /** | ||
| * A unique identifier for the field. | ||
| */ | ||
| readonly key: string; | ||
| } | ||
|
|
||
| export interface AiExtractStructuredFieldsField { | ||
| /** | ||
| * A unique identifier for the field. | ||
| */ | ||
| readonly key: string; | ||
| /** | ||
| * A description of the field. | ||
| */ | ||
| readonly description?: string; | ||
| /** | ||
| * The display name of the field. | ||
| */ | ||
| readonly display_name?: string; | ||
| /** | ||
| * Context about the key that may include how to find and how to format it. | ||
| */ | ||
| readonly prompt?: string; | ||
| /** | ||
| * The type of the field. Can include but is not limited to string, float, date, enum, and multiSelect. | ||
| */ | ||
| readonly type?: string; | ||
| /** | ||
| * A list of options for this field. This is most often used in combination with the enum and multiSelect field | ||
| * types. | ||
| */ | ||
| readonly options?: ReadonlyArray<AiExtractStructuredFieldsOptionsField>; | ||
| } | ||
|
|
||
| export interface AiExtractStructured { | ||
| /** | ||
| * The items to be processed by the LLM, often files. | ||
| */ | ||
| readonly items: ReadonlyArray<AiItemBase>; | ||
| /** | ||
| * The metadata template containing the fields to extract. Cannot be used in combination with `fields`. | ||
| */ | ||
| readonly metadata_template?: AiExtractStructuredMetadataTemplateField; | ||
| /** | ||
| * The fields to be extracted from the items. Cannot be used in combination with `metadata_template`. | ||
| */ | ||
| readonly fields?: ReadonlyArray<AiExtractStructuredFieldsField>; | ||
| /** | ||
| * The JSON blob that contains overrides for the agent config. | ||
| */ | ||
| readonly agent_config?: string; | ||
| /** | ||
| * The AI Agent definition to use for extraction. Use `AiAgentExtractStructured` to customize basic-text or | ||
| * long-text agents, or `AiAgentReference` to reference a custom AI Agent by ID. | ||
| */ | ||
| readonly ai_agent?: AiAgentExtractStructured | AiAgentReference; | ||
| /** | ||
| * When `true`, the response includes confidence scores for each extracted field. | ||
| */ | ||
| readonly include_confidence_score?: boolean; | ||
| /** | ||
| * When `true`, the response includes reference locations (bounding boxes) for each extracted field. | ||
| */ | ||
| readonly include_reference?: boolean; | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| export type AiItemBaseTypeField = 'file'; | ||
|
|
||
| export interface AiItemBase { | ||
| /** | ||
| * The ID of the item. | ||
| */ | ||
| readonly id: string; | ||
| /** | ||
| * The type of the item. | ||
| */ | ||
| readonly type: AiItemBaseTypeField; | ||
| /** | ||
| * The content of the item, often the text representation. | ||
| */ | ||
| readonly content?: string; | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| export type AiLlmEndpointParamsGoogleTypeField = 'google_params'; | ||
|
|
||
| export interface AiLlmEndpointParamsGoogle { | ||
| /** | ||
| * The type of the AI LLM endpoint params object for Google. | ||
| */ | ||
| readonly type: AiLlmEndpointParamsGoogleTypeField; | ||
| /** | ||
| * The sampling temperature used during response generation. Temperature controls the degree of randomness in token | ||
| * selection. | ||
| */ | ||
| readonly temperature?: number; | ||
| /** | ||
| * The cumulative probability threshold used to select output tokens. | ||
| */ | ||
| readonly top_p?: number; | ||
| /** | ||
| * The number of most probable tokens considered when selecting the next token. | ||
| */ | ||
| readonly top_k?: number; | ||
| } |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
src/api/schemas/AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| import type { AiLlmEndpointParamsGoogle } from './AiLlmEndpointParamsGoogle'; | ||
| import type { AiLlmEndpointParamsOpenAi } from './AiLlmEndpointParamsOpenAi'; | ||
|
|
||
| export type AiLlmEndpointParamsGoogleOrAiLlmEndpointParamsOpenAi = | ||
| | AiLlmEndpointParamsGoogle | ||
| | AiLlmEndpointParamsOpenAi; |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * @author Box | ||
| */ | ||
|
|
||
| export type AiLlmEndpointParamsOpenAiTypeField = 'openai_params'; | ||
|
|
||
| export interface AiLlmEndpointParamsOpenAi { | ||
| /** | ||
| * The type of the AI LLM endpoint params object for OpenAI. | ||
| */ | ||
| readonly type: AiLlmEndpointParamsOpenAiTypeField; | ||
| /** | ||
| * The sampling temperature, between 0 and 2. Higher values make the output more random, while lower values make it | ||
| * more focused and deterministic. Alter this or `top_p`, but not both. | ||
| */ | ||
| readonly temperature?: number; | ||
| /** | ||
| * The nucleus sampling probability mass. Alter this or `temperature`, but not both. | ||
| */ | ||
| readonly top_p?: number; | ||
| /** | ||
| * A number between -2.0 and 2.0 that penalizes new tokens based on their existing frequency in the generated text. | ||
| */ | ||
| readonly frequency_penalty?: number; | ||
| /** | ||
| * A number between -2.0 and 2.0 that penalizes new tokens based on whether they appear in the generated text. | ||
| */ | ||
| readonly presence_penalty?: number; | ||
| /** | ||
| * Up to four sequences where the API stops generating further tokens. | ||
| */ | ||
| readonly stop?: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: box/box-ui-elements
Length of output: 3680
🌐 Web query:
Box developer API ai_agent_extract_structured basic_image AiAgentBasicTextTool💡 Result:
The
ai_agent_extract_structuredis a configuration type for the Box AI API used specifically with thePOST /ai/extract_structuredendpoint [1][2][3]. This endpoint allows developers to extract structured metadata (key-value pairs) from files [1][2]. When configuring theai_agentobject for this request, you can use thebasic_imagetool, which is defined by theAiAgentBasicTextToolschema [4][5]. Despite its name, thebasic_imagetool—along withbasic_textandlong_text—is part of the structured extraction agent configuration [4][5]. Key components of the configuration: 1. ai_agent_extract_structured: The primary agent type required for structured metadata extraction [4][5]. 2. AiAgentBasicTextTool: This schema is used forbasic_text,long_text, andbasic_imagefields within the agent configuration [4][5]. It includes parameters such as: - model: Specifies the LLM to use (e.g., azureopenaigpt_4o_mini) [4]. - system_message: Helps define the role and behavior of the LLM [6][7]. - prompt_template: Defines the instructions for the AI, which must include placeholders for {user_question} and {content} [6][7]. - llm_endpoint_params: Allows for fine-tuning LLM behavior (e.g., temperature, top_p) [4][8]. ThePOST /ai/extract_structuredendpoint supports file formats including PDF, TIFF, PNG, and JPEG, with automatic OCR capabilities [3]. You can retrieve default agent configurations using theGET /2.0/ai_agent_defaultendpoint to see how these fields are structured for your specific use case [5][3].Citations:
🏁 Script executed:
Repository: box/box-ui-elements
Length of output: 7538
🏁 Script executed:
Repository: box/box-ui-elements
Length of output: 7616
Add
basic_imageto both structured-agent declarations.The Box API supports
basic_imagewithAiAgentBasicTextToolforai_agent_extract_structured.AiExtractStructured.ai_agentacceptsAiAgentExtractStructured, so TypeScript callers can be blocked from passing this documented property in object literals. Add the field to both declarations.📍 Affects 2 files
src/api/schemas/AiAgentExtractStructured.ts#L18-L22(this comment)src/api/schemas/AiAgentExtractStructured.js.flow#L15-L17🤖 Prompt for AI Agents