Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export type {
IdentificationStatus,
IdentifyParams,
DocumentType,
ConversionMode,
ValidationErrorInfo,
ValidationWarningInfo,
ValidationResult,
Expand Down
11 changes: 9 additions & 2 deletions src/types/document-type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Conversion mode used when extracting from a document type.
*/
export type ConversionMode = 'json' | 'toon' | 'multi_prompt';

/**
* A document type definition from the API.
*/
Expand All @@ -22,6 +27,8 @@ export interface DocumentType {
updatedAt: string | null;
/** The JSON Schema defining the extraction structure. */
jsonSchema: Record<string, unknown> | null;
/** Conversion mode used when extracting from this document type. */
conversionMode?: ConversionMode;
}

/**
Expand Down Expand Up @@ -73,7 +80,7 @@ export interface DocumentTypeCreateParams {
/** Hints to guide the identification prompt. */
identifyPromptHints?: string;
/** The conversion mode to use. */
conversionMode?: 'json' | 'toon' | 'multi_prompt';
conversionMode?: ConversionMode;
/** Whether to preserve property ordering in extraction output. */
keepPropertyOrdering?: boolean;
/** Whether the document type is publicly available. */
Expand All @@ -97,7 +104,7 @@ export interface DocumentTypeUpdateParams {
/** Updated identification prompt hints. */
identifyPromptHints?: string;
/** Updated conversion mode. */
conversionMode?: 'json' | 'toon' | 'multi_prompt';
conversionMode?: ConversionMode;
/** Whether to preserve property ordering. */
keepPropertyOrdering?: boolean;
/** Whether the document type is publicly available. */
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export {

// Document type types
export type {
ConversionMode,
DocumentType,
DocumentTypeCreateParams,
DocumentTypeUpdateParams,
Expand Down
2 changes: 2 additions & 0 deletions tests/helpers/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const mockDocumentType: DocumentType = {
createdAt: '2025-01-01T00:00:00Z',
updatedAt: '2025-01-01T00:00:00Z',
jsonSchema: { fields: ['total', 'date'] },
conversionMode: 'json',
};

export const mockDocumentTypeCreated: DocumentType = {
Expand All @@ -85,6 +86,7 @@ export const mockDocumentTypeCreated: DocumentType = {
createdAt: '2025-06-01T00:00:00Z',
updatedAt: '2025-06-01T00:00:00Z',
jsonSchema: { fields: ['total', 'merchant'] },
conversionMode: 'multi_prompt',
};

export const mockValidationResult: ValidationResult = {
Expand Down
18 changes: 18 additions & 0 deletions tests/resources/document-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { server, http, HttpResponse } from '../helpers/mock-server.js';
import { DocumentTypes } from '../../src/resources/document-types.js';
import { APIClient } from '../../src/core/api-client.js';
import { RawResponse } from '../../src/core/raw-response.js';
import type { ConversionMode } from '../../src/types/document-type.js';
import {
TEST_BASE_URL,
mockDocumentType,
Expand Down Expand Up @@ -98,6 +99,23 @@ describe('DocumentTypes', () => {
expect(result.name).toBe('Invoice');
expect(result.codeType).toBe('invoice');
expect(result.jsonSchema).toEqual({ fields: ['total', 'date'] });
expect(result.conversionMode).toBe('json');
});

it('exposes conversionMode without requiring a cast', async () => {
server.use(
http.get(`${TEST_BASE_URL}/api/document-types/dt-789`, () => {
return HttpResponse.json({
data: { ...mockDocumentType, conversionMode: 'toon' },
});
}),
);

const dt = createDocumentTypes();
const result = await dt.get('dt-789');

const mode: ConversionMode | undefined = result.conversionMode;
expect(mode).toBe('toon');
});
});

Expand Down
Loading