From 716dcb6dcf28392a8e127c01af99d7170f806126 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 19:49:03 +0000 Subject: [PATCH 1/2] Initial plan From 85e21725984eef1e332dbcf4a50fafbeee2f6ca8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 19:54:21 +0000 Subject: [PATCH 2/2] feat: wrap Feishu document AI invoice recognition APIs in DocumentAIModel --- src/Lark.ts | 5 +++ src/module/DocumentAI/index.ts | 60 ++++++++++++++++++++++++++++++++++ src/module/DocumentAI/type.ts | 17 ++++++++++ src/module/index.ts | 1 + 4 files changed, 83 insertions(+) create mode 100644 src/module/DocumentAI/index.ts create mode 100644 src/module/DocumentAI/type.ts diff --git a/src/Lark.ts b/src/Lark.ts index 10b4786..c44bc64 100644 --- a/src/Lark.ts +++ b/src/Lark.ts @@ -6,6 +6,7 @@ import { BiTableSchema, BiTableView, CopiedFile, + DocumentAIModel, DocumentModel, DriveFileModel, TableFormView, @@ -51,6 +52,7 @@ export class LarkApp implements LarkAppOption { driveFileStore: DriveFileModel; wikiNodeStore: WikiNodeModel; documentStore: DocumentModel; + documentAIStore: DocumentAIModel; constructor(option: LarkAppServerOption | LarkAppClientOption) { Object.assign(this, option); @@ -74,6 +76,9 @@ export class LarkApp implements LarkAppOption { this.documentStore = new (class extends DocumentModel { client = client; })(''); + this.documentAIStore = new (class extends DocumentAIModel { + client = client; + })(); } private boot() { diff --git a/src/module/DocumentAI/index.ts b/src/module/DocumentAI/index.ts new file mode 100644 index 0000000..8f779ce --- /dev/null +++ b/src/module/DocumentAI/index.ts @@ -0,0 +1,60 @@ +import { makeFormData } from 'koajax'; +import { BaseModel, RESTClient, toggle } from 'mobx-restful'; + +import { LarkData } from '../../type'; +import { TaxiInvoice, TrainInvoice, VatInvoice, VehicleInvoice } from './type'; + +export * from './type'; + +export abstract class DocumentAIModel extends BaseModel { + baseURI = 'document_ai/v1'; + abstract client: RESTClient; + + /** + * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/vat_invoice/recognize} + */ + @toggle('uploading') + async recognizeVatInvoice(file: File) { + const { body } = await this.client.post>( + `${this.baseURI}/vat_invoice/recognize`, + makeFormData({ file }) + ); + return body!.data!.vat_invoices; + } + + /** + * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/taxi_invoice/recognize} + */ + @toggle('uploading') + async recognizeTaxiInvoice(file: File) { + const { body } = await this.client.post>( + `${this.baseURI}/taxi_invoice/recognize`, + makeFormData({ file }) + ); + return body!.data!.taxi_invoices; + } + + /** + * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/train_invoice/recognize} + */ + @toggle('uploading') + async recognizeTrainInvoice(file: File) { + const { body } = await this.client.post>( + `${this.baseURI}/train_invoice/recognize`, + makeFormData({ file }) + ); + return body!.data!.train_invoices; + } + + /** + * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/vehicle_invoice/recognize} + */ + @toggle('uploading') + async recognizeVehicleInvoice(file: File) { + const { body } = await this.client.post>( + `${this.baseURI}/vehicle_invoice/recognize`, + makeFormData({ file }) + ); + return body!.data!.vehicle_invoices; + } +} diff --git a/src/module/DocumentAI/type.ts b/src/module/DocumentAI/type.ts new file mode 100644 index 0000000..7b0b72e --- /dev/null +++ b/src/module/DocumentAI/type.ts @@ -0,0 +1,17 @@ +export interface InvoiceEntity { + type: string; + value: string; + score: number; +} + +export interface Invoice { + entities: InvoiceEntity[]; +} + +export type VatInvoice = Invoice; + +export type TaxiInvoice = Invoice; + +export type TrainInvoice = Invoice; + +export type VehicleInvoice = Invoice; diff --git a/src/module/index.ts b/src/module/index.ts index 0e15ce8..dfe010f 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -8,3 +8,4 @@ export * from './SpreadSheet'; export * from './BITable'; export * from './Drive'; export * from './Wiki'; +export * from './DocumentAI';