From b264d1f6ac0f061b3eefa0c6cc0a5bcedb24f342 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 21:35:46 +0000 Subject: [PATCH 1/2] Initial plan From 24a4ad9855518a5f210f0b1246c590e6b213c658 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 21:40:30 +0000 Subject: [PATCH 2/2] [add] OCR, bank card, resume, and contract field extraction APIs to DocumentAIModel --- src/module/DocumentAI/index.ts | 61 +++++++++++++++++++++++++++++++++- src/module/DocumentAI/type.ts | 45 +++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/src/module/DocumentAI/index.ts b/src/module/DocumentAI/index.ts index 06f68f4..18cc52e 100644 --- a/src/module/DocumentAI/index.ts +++ b/src/module/DocumentAI/index.ts @@ -2,7 +2,16 @@ import { makeFormData } from 'koajax'; import { BaseModel, RESTClient, toggle } from 'mobx-restful'; import { LarkData } from '../../type'; -import { TaxiInvoice, TrainInvoice, VatInvoice, VehicleInvoice } from './type'; +import { + BankCard, + ContractEntity, + OcrText, + ResumeEntity, + TaxiInvoice, + TrainInvoice, + VatInvoice, + VehicleInvoice +} from './type'; export * from './type'; @@ -58,4 +67,54 @@ export abstract class DocumentAIModel extends BaseModel { return body!.data!.vehicle_invoice; } + + /** + * @see {@link https://open.feishu.cn/document/server-docs/ai/optical_char_recognition-v1/basic_recognize} + * @param image Base64-encoded image string + */ + @toggle('uploading') + async recognizeText(image: string) { + const { body } = await this.client.post>( + 'optical_char_recognition/v1/image/basic_recognize', + { image } + ); + + return body!.data!.texts; + } + + /** + * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/bank_card/recognize} + */ + @toggle('uploading') + async recognizeBankCard(file: File) { + const { body } = await this.client.post< + LarkData<{ bank_cards: { entities: BankCard[] }[] }> + >(`${this.baseURI}/bank_card/recognize`, makeFormData({ file })); + + return body!.data!.bank_cards; + } + + /** + * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/resume/parse} + */ + @toggle('uploading') + async parseResume(file: File) { + const { body } = await this.client.post< + LarkData<{ resumes: { entities: ResumeEntity[] }[] }> + >(`${this.baseURI}/resume/parse`, makeFormData({ file })); + + return body!.data!.resumes; + } + + /** + * @see {@link https://open.feishu.cn/document/server-docs/ai/document_ai-v1/contract/field_extraction} + */ + @toggle('uploading') + async extractContractFields(file: File) { + const { body } = await this.client.post< + LarkData<{ contracts: { entities: ContractEntity[] }[] }> + >(`${this.baseURI}/contract/field_extraction`, makeFormData({ file })); + + return body!.data!.contracts; + } } diff --git a/src/module/DocumentAI/type.ts b/src/module/DocumentAI/type.ts index fdb682e..56bdc74 100644 --- a/src/module/DocumentAI/type.ts +++ b/src/module/DocumentAI/type.ts @@ -67,3 +67,48 @@ export interface VehicleInvoice { | `total_price${'' | '_little'}`; value: string; } + +export interface OcrText { + text: string; + /** Array of corner points (top-left, top-right, bottom-right, bottom-left) for the text bounding box */ + positions: { x: number; y: number }[]; +} + +export interface BankCard { + type: 'bank_card_number' | 'bank_card_date_of_expiry'; + value: string; +} + +export interface ResumeEntity { + type: + | 'name' + | 'gender' + | 'date_of_birth' + | 'marital_status' + | 'nationality' + | 'job_title' + | 'email' + | 'phone' + | 'address' + | `${'education' | 'work_experience' | 'project_experience' | 'award'}_history` + | 'self_description' + | 'skills' + | 'certificates' + | 'languages'; + value: string; +} + +export interface ContractEntity { + type: + | 'contract_name' + | 'contract_type' + | 'contract_amount' + | 'contract_period' + | 'sign_date' + | 'effective_date' + | 'expiration_date' + | 'terms_of_payment' + | `party_${'a' | 'b'}` + | `party_${'a' | 'b'}_signatory`; + value: string; +}