-
- Metered Feature
- Credit Cost
-
+
+ {!disableModeSwitch && (
+
+ )}
-
- {schema.map((item: CreditSchemaItem, index: number) => {
- const availableFeatures = allMeteredFeatures.filter(
- (feature: Feature) =>
- !schema.some(
- (schemaItem: CreditSchemaItem) =>
- feature.id !== item.metered_feature_id &&
- schemaItem.metered_feature_id === feature.id,
- ),
- );
-
- return (
-
- );
- })}
-
-
-
= allMeteredFeatures.length}
- className="w-fit mt-4"
- icon={}
- >
- Add
-
+ {mode === "classic" ? (
+
+ ) : (
+
+ )}
);
diff --git a/vite/src/views/products/features/credit-systems/components/UpdateCreditSystemSheet.tsx b/vite/src/views/products/features/credit-systems/components/UpdateCreditSystemSheet.tsx
index 16d280699..de9b800bc 100644
--- a/vite/src/views/products/features/credit-systems/components/UpdateCreditSystemSheet.tsx
+++ b/vite/src/views/products/features/credit-systems/components/UpdateCreditSystemSheet.tsx
@@ -59,6 +59,7 @@ function UpdateCreditSystemSheet({
type: selectedCreditSystem.type,
config: selectedCreditSystem.config,
event_names: selectedCreditSystem.event_names,
+ model_markups: selectedCreditSystem.model_markups,
});
}
}, [open, selectedCreditSystem]);
@@ -74,6 +75,8 @@ function UpdateCreditSystemSheet({
setLoading(true);
try {
+ const isAiCreditSystem = creditSystem.type === FeatureType.AiCreditSystem;
+
await FeatureService.updateFeature(
axiosInstance,
selectedCreditSystem.id,
@@ -81,12 +84,14 @@ function UpdateCreditSystemSheet({
id: creditSystem.id,
name: creditSystem.name,
type: creditSystem.type,
- credit_schema: creditSystem.config?.schema?.map(
- (x: CreditSchemaItem) => ({
- metered_feature_id: x.metered_feature_id,
- credit_cost: Number(x.credit_amount),
- }),
- ),
+ model_markups: creditSystem.model_markups ?? undefined,
+ credit_schema: isAiCreditSystem
+ ? undefined
+ : creditSystem.config?.schema?.map((x: CreditSchemaItem) => ({
+ metered_feature_id: x.metered_feature_id,
+ credit_cost:
+ x.credit_amount != null ? Number(x.credit_amount) : 0,
+ })),
event_names: creditSystem.event_names,
display: undefined,
},
@@ -95,7 +100,6 @@ function UpdateCreditSystemSheet({
await refetch();
toast.success("Credit system updated successfully");
- // Call onSuccess with old and new IDs
if (onSuccess) {
onSuccess(
selectedCreditSystem.id,
@@ -105,7 +109,6 @@ function UpdateCreditSystemSheet({
setOpen(false);
} catch (error: unknown) {
- console.log(error);
toast.error(
getBackendErr(error as AxiosError, "Failed to update credit system"),
);
@@ -134,6 +137,7 @@ function UpdateCreditSystemSheet({
diff --git a/vite/src/views/products/features/credit-systems/hooks/useAiCreditSchema.ts b/vite/src/views/products/features/credit-systems/hooks/useAiCreditSchema.ts
new file mode 100644
index 000000000..0f3001eb0
--- /dev/null
+++ b/vite/src/views/products/features/credit-systems/hooks/useAiCreditSchema.ts
@@ -0,0 +1,259 @@
+import type { CreateFeature } from "@autumn/shared";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { toast } from "sonner";
+import { useModelsDevPricing } from "@/hooks/queries/useAiModelsQuery";
+
+type ModelMarkupEntry = {
+ markup: number;
+ input_cost?: number;
+ output_cost?: number;
+};
+
+type ModelMarkups = Record