Skip to content
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

Enable pricing via tasks #866

Merged
merged 1 commit into from
Nov 8, 2024
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
10 changes: 8 additions & 2 deletions documentation/src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SteeringWheelPosition,
TaskName,
VehicleType,
BusinessClients,
} from '@monkvision/types';
import { sights } from '@monkvision/sights';
import { flatten } from '@monkvision/common';
Expand Down Expand Up @@ -191,10 +192,16 @@ export const CreateHinlTaskOptionsSchema = z.object({
callbacks: z.array(TaskCallbackOptionsSchema).optional(),
});

export const CreatePricingTaskOptionsSchema = z.object({
name: z.literal(TaskName.PRICING),
outputFormat: z.nativeEnum(BusinessClients).optional(),
});

export const InspectionCreateTaskSchema = z
.nativeEnum(TaskName)
.or(CreateDamageDetectionTaskOptionsSchema)
.or(CreateDamageDetectionTaskOptionsSchema);
.or(CreateHinlTaskOptionsSchema)
.or(CreatePricingTaskOptionsSchema);

export const AdditionalDataSchema = z.record(z.string(), z.unknown());

Expand Down Expand Up @@ -225,7 +232,6 @@ export const CreateInspectionOptionsSchema = z.object({
tasks: z.array(InspectionCreateTaskSchema),
vehicle: InspectionCreateVehicleSchema.optional(),
useDynamicCrops: z.boolean().optional(),
usePricingV2: z.boolean().optional(),
additionalData: AdditionalDataSchema.optional(),
});

Expand Down
24 changes: 23 additions & 1 deletion packages/network/src/api/inspection/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CreateDamageDetectionTaskOptions,
CreateHinlTaskOptions,
CreateInspectionOptions,
CreatePricingTaskOptions,
CurrencyCode,
CustomSeverityValue,
Damage,
Expand Down Expand Up @@ -40,6 +41,7 @@ import {
ApiInspectionGet,
ApiInspectionPost,
ApiPartSeverityValue,
ApiPricingTaskPostComponent,
ApiPricingV2Details,
ApiRenderedOutput,
ApiSeverityResult,
Expand Down Expand Up @@ -486,12 +488,33 @@ function getImagesOCROptions(
: undefined;
}

function getPricingOptions(
options: CreateInspectionOptions,
): ApiPricingTaskPostComponent | undefined {
if (options.tasks.includes(TaskName.PRICING)) {
return {
status: ProgressStatus.TODO,
output_format: 'default',
};
}
const taskOptions = options.tasks.find(
(task) => typeof task === 'object' && task.name === TaskName.PRICING,
) as CreatePricingTaskOptions | undefined;
return taskOptions
? {
status: ProgressStatus.TODO,
output_format: taskOptions.outputFormat ?? 'default',
}
: undefined;
}

function getTasksOptions(options: CreateInspectionOptions): ApiTasksComponent {
return {
damage_detection: getDamageDetectionOptions(options),
wheel_analysis: getWheelAnalysisOptions(options),
images_ocr: getImagesOCROptions(options),
human_in_the_loop: getHumanInTheLoopOptions(options),
pricing: getPricingOptions(options),
};
}

Expand Down Expand Up @@ -534,7 +557,6 @@ export function mapApiInspectionPost(options: CreateInspectionOptions): ApiInspe
}
: undefined,
damage_severity: { output_format: 'default' },
pricing: options.usePricingV2 ? { output_format: 'default' } : undefined,
additional_data: {
user_agent: navigator.userAgent,
connection: navigator.connection,
Expand Down
5 changes: 1 addition & 4 deletions packages/network/src/api/models/inspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ApiImagePost, ApiImages } from './image';
import type { ApiParts } from './part';
import type { ApiPricingV2 } from './pricingV2';
import type { ApiSeverityResults } from './severityResult';
import type { ApiTasks } from './task';
import type { ApiBusinessClients, ApiTasks } from './task';
import type { ApiVehicleComponent } from './vehicle';
import type { ApiWheelAnalysis } from './wheelAnalysis';
import { ApiVehiclePostPatch } from './vehicle';
Expand All @@ -29,8 +29,6 @@ export interface ApiInspectionGet {
wheel_analysis?: ApiWheelAnalysis;
}

export type ApiBusinessClients = 'default' | 'toyota' | 'veb';

export interface ApiDamageSeverity {
output_format: ApiBusinessClients;
}
Expand All @@ -41,5 +39,4 @@ export interface ApiInspectionPost {
images?: ApiImagePost[];
vehicle?: ApiVehiclePostPatch;
damage_severity?: ApiDamageSeverity;
pricing?: ApiDamageSeverity;
}
9 changes: 9 additions & 0 deletions packages/network/src/api/models/task.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type ApiBusinessClients = 'default' | 'toyota' | 'veb' | 'tesla';

export interface ApiImageInTask {
image_id: string;
}
Expand Down Expand Up @@ -107,9 +109,16 @@ export interface ApiHinlTaskPostComponent {
callbacks?: ApiCallbacks;
}

export interface ApiPricingTaskPostComponent {
status?: ApiTaskPostProgressStatus;
callbacks?: ApiCallbacks;
output_format?: ApiBusinessClients;
}

export interface ApiTasksComponent {
damage_detection?: ApiDamageDetectionTaskPostComponent;
wheel_analysis?: ApiWheelAnalysisTaskPostComponent;
images_ocr?: ApiImagesOCRTaskPostComponent;
human_in_the_loop?: ApiHinlTaskPostComponent;
pricing?: ApiPricingTaskPostComponent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"wheel_analysis": {
"status": "NOT_STARTED",
"use_longshots": true
},
"pricing": {
"status": "TODO",
"output_format": "default"
}
},
"vehicle": {
Expand Down Expand Up @@ -50,9 +54,6 @@
"damage_severity": {
"output_format": "default"
},
"pricing": {
"output_format": "default"
},
"additional_data": {
"damage_detection_version": "v2",
"use_dynamic_crops": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
generateSubimageDamages: true,
generateSubimageParts: true,
},
TaskName.PRICING,
],
vehicle: {
brand: 'brand',
Expand Down Expand Up @@ -39,7 +40,6 @@ export default {
},
},
useDynamicCrops: true,
usePricingV2: true,
isVideoCapture: true,
additionalData: {
test: 'uno',
Expand Down
47 changes: 40 additions & 7 deletions packages/types/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ export enum MonkApiPermission {
INSPECTION_WRITE_ORGANIZATION = 'monk_core_api:inspections:write_organization',
}

/**
* Enumeration of Monk response format.
*/
export enum BusinessClients {
/**
* Default format.
*/
DEFAULT = 'default',
/**
* Toyota format.
*/
TOYOTA = 'toyota',
/**
* Veb format.
*/
VEB = 'veb',
/**
* Tesla format.
*/
TESLA = 'tesla',
}

/**
* Options used to specify a callback that will be called by the API when a task is complete.
*/
Expand Down Expand Up @@ -97,14 +119,31 @@ export interface CreateHinlTaskOptions {
callbacks?: TaskCallbackOptions[];
}

/**
* Additional options that you can specify when adding the pricing task to an inspection.
*/
export interface CreatePricingTaskOptions {
/**
* The name of the task : `TaskName.PRICING`.
*/
name: TaskName.PRICING;
/**
* The client's output format.
*
* @default 'default'
*/
outputFormat?: BusinessClients;
}

/**
* The tasks of the inspection to be created. It is either simply the name of the task to add, or an object with the
* task name as well as additional configuration options for the task.
*/
export type InspectionCreateTask =
| TaskName
| CreateDamageDetectionTaskOptions
| CreateHinlTaskOptions;
| CreateHinlTaskOptions
| CreatePricingTaskOptions;

/**
* Options that can be specified when creating a new inspection.
Expand All @@ -125,12 +164,6 @@ export interface CreateInspectionOptions {
* @default true
*/
useDynamicCrops?: boolean;
/**
* Boolean indicating if the pricing V2 (format Toyota) should be enabled or not.
*
* @default false
*/
usePricingV2?: boolean;
/**
* Boolean indicating if the inspection to create will be used with the VideoCapture workflow or not.
*
Expand Down