intentkit 0.6.17.dev3__py3-none-any.whl → 0.6.19.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of intentkit might be problematic. Click here for more details.
- intentkit/__init__.py +1 -1
- intentkit/core/credit.py +235 -103
- intentkit/models/credit.py +44 -4
- {intentkit-0.6.17.dev3.dist-info → intentkit-0.6.19.dev1.dist-info}/METADATA +1 -1
- {intentkit-0.6.17.dev3.dist-info → intentkit-0.6.19.dev1.dist-info}/RECORD +7 -7
- {intentkit-0.6.17.dev3.dist-info → intentkit-0.6.19.dev1.dist-info}/WHEEL +0 -0
- {intentkit-0.6.17.dev3.dist-info → intentkit-0.6.19.dev1.dist-info}/licenses/LICENSE +0 -0
intentkit/__init__.py
CHANGED
intentkit/core/credit.py
CHANGED
|
@@ -117,8 +117,9 @@ async def recharge(
|
|
|
117
117
|
session=session,
|
|
118
118
|
owner_type=OwnerType.USER,
|
|
119
119
|
owner_id=user_id,
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
amount_details={
|
|
121
|
+
CreditType.PERMANENT: amount
|
|
122
|
+
}, # Recharge adds to permanent credits
|
|
122
123
|
event_id=event_id,
|
|
123
124
|
)
|
|
124
125
|
|
|
@@ -168,6 +169,9 @@ async def recharge(
|
|
|
168
169
|
credit_debit=CreditDebit.CREDIT,
|
|
169
170
|
change_amount=amount,
|
|
170
171
|
credit_type=CreditType.PERMANENT,
|
|
172
|
+
free_amount=Decimal("0"),
|
|
173
|
+
reward_amount=Decimal("0"),
|
|
174
|
+
permanent_amount=amount,
|
|
171
175
|
)
|
|
172
176
|
session.add(user_tx)
|
|
173
177
|
|
|
@@ -180,6 +184,9 @@ async def recharge(
|
|
|
180
184
|
credit_debit=CreditDebit.DEBIT,
|
|
181
185
|
change_amount=amount,
|
|
182
186
|
credit_type=CreditType.PERMANENT,
|
|
187
|
+
free_amount=Decimal("0"),
|
|
188
|
+
reward_amount=Decimal("0"),
|
|
189
|
+
permanent_amount=amount,
|
|
183
190
|
)
|
|
184
191
|
session.add(platform_tx)
|
|
185
192
|
|
|
@@ -239,8 +246,7 @@ async def reward(
|
|
|
239
246
|
session=session,
|
|
240
247
|
owner_type=OwnerType.USER,
|
|
241
248
|
owner_id=user_id,
|
|
242
|
-
|
|
243
|
-
credit_type=CreditType.REWARD, # Reward adds to reward credits
|
|
249
|
+
amount_details={CreditType.REWARD: amount}, # Reward adds to reward credits
|
|
244
250
|
event_id=event_id,
|
|
245
251
|
)
|
|
246
252
|
|
|
@@ -290,6 +296,9 @@ async def reward(
|
|
|
290
296
|
credit_debit=CreditDebit.CREDIT,
|
|
291
297
|
change_amount=amount,
|
|
292
298
|
credit_type=CreditType.REWARD,
|
|
299
|
+
free_amount=Decimal("0"),
|
|
300
|
+
reward_amount=amount,
|
|
301
|
+
permanent_amount=Decimal("0"),
|
|
293
302
|
)
|
|
294
303
|
session.add(user_tx)
|
|
295
304
|
|
|
@@ -302,6 +311,9 @@ async def reward(
|
|
|
302
311
|
credit_debit=CreditDebit.DEBIT,
|
|
303
312
|
change_amount=amount,
|
|
304
313
|
credit_type=CreditType.REWARD,
|
|
314
|
+
free_amount=Decimal("0"),
|
|
315
|
+
reward_amount=amount,
|
|
316
|
+
permanent_amount=Decimal("0"),
|
|
305
317
|
)
|
|
306
318
|
session.add(platform_tx)
|
|
307
319
|
|
|
@@ -375,8 +387,7 @@ async def adjustment(
|
|
|
375
387
|
session=session,
|
|
376
388
|
owner_type=OwnerType.USER,
|
|
377
389
|
owner_id=user_id,
|
|
378
|
-
|
|
379
|
-
credit_type=credit_type,
|
|
390
|
+
amount_details={credit_type: abs_amount},
|
|
380
391
|
event_id=event_id,
|
|
381
392
|
)
|
|
382
393
|
else:
|
|
@@ -407,8 +418,7 @@ async def adjustment(
|
|
|
407
418
|
session=session,
|
|
408
419
|
owner_type=OwnerType.PLATFORM,
|
|
409
420
|
owner_id=DEFAULT_PLATFORM_ACCOUNT_ADJUSTMENT,
|
|
410
|
-
|
|
411
|
-
credit_type=credit_type,
|
|
421
|
+
amount_details={credit_type: abs_amount},
|
|
412
422
|
event_id=event_id,
|
|
413
423
|
)
|
|
414
424
|
|
|
@@ -460,6 +470,9 @@ async def adjustment(
|
|
|
460
470
|
credit_debit=credit_debit_user,
|
|
461
471
|
change_amount=abs_amount,
|
|
462
472
|
credit_type=credit_type,
|
|
473
|
+
free_amount=free_amount,
|
|
474
|
+
reward_amount=reward_amount,
|
|
475
|
+
permanent_amount=permanent_amount,
|
|
463
476
|
)
|
|
464
477
|
session.add(user_tx)
|
|
465
478
|
|
|
@@ -472,6 +485,9 @@ async def adjustment(
|
|
|
472
485
|
credit_debit=credit_debit_platform,
|
|
473
486
|
change_amount=abs_amount,
|
|
474
487
|
credit_type=credit_type,
|
|
488
|
+
free_amount=free_amount,
|
|
489
|
+
reward_amount=reward_amount,
|
|
490
|
+
permanent_amount=permanent_amount,
|
|
475
491
|
)
|
|
476
492
|
session.add(platform_tx)
|
|
477
493
|
|
|
@@ -842,34 +858,7 @@ async def expense_message(
|
|
|
842
858
|
session=session, id=agent.id, amount=details.get(CreditType.FREE)
|
|
843
859
|
)
|
|
844
860
|
|
|
845
|
-
# 3.
|
|
846
|
-
message_account = await CreditAccount.income_in_session(
|
|
847
|
-
session=session,
|
|
848
|
-
owner_type=OwnerType.PLATFORM,
|
|
849
|
-
owner_id=DEFAULT_PLATFORM_ACCOUNT_MESSAGE,
|
|
850
|
-
credit_type=CreditType.PERMANENT,
|
|
851
|
-
amount=base_amount,
|
|
852
|
-
event_id=event_id,
|
|
853
|
-
)
|
|
854
|
-
platform_fee_account = await CreditAccount.income_in_session(
|
|
855
|
-
session=session,
|
|
856
|
-
owner_type=OwnerType.PLATFORM,
|
|
857
|
-
owner_id=DEFAULT_PLATFORM_ACCOUNT_FEE,
|
|
858
|
-
credit_type=CreditType.PERMANENT,
|
|
859
|
-
amount=fee_platform_amount,
|
|
860
|
-
event_id=event_id,
|
|
861
|
-
)
|
|
862
|
-
if fee_agent_amount > 0:
|
|
863
|
-
agent_account = await CreditAccount.income_in_session(
|
|
864
|
-
session=session,
|
|
865
|
-
owner_type=OwnerType.AGENT,
|
|
866
|
-
owner_id=agent.id,
|
|
867
|
-
credit_type=CreditType.REWARD,
|
|
868
|
-
amount=fee_agent_amount,
|
|
869
|
-
event_id=event_id,
|
|
870
|
-
)
|
|
871
|
-
|
|
872
|
-
# 4. Create credit event record
|
|
861
|
+
# 3. Calculate detailed amounts for fees based on user payment details
|
|
873
862
|
# Set the appropriate credit amount field based on credit type
|
|
874
863
|
free_amount = details.get(CreditType.FREE, Decimal("0"))
|
|
875
864
|
reward_amount = details.get(CreditType.REWARD, Decimal("0"))
|
|
@@ -925,6 +914,52 @@ async def expense_message(
|
|
|
925
914
|
fee_agent_amount - fee_agent_free_amount - fee_agent_reward_amount
|
|
926
915
|
).quantize(FOURPLACES, rounding=ROUND_HALF_UP)
|
|
927
916
|
|
|
917
|
+
# Calculate base amounts by credit type using subtraction method
|
|
918
|
+
# This ensures that: permanent_amount = base_permanent_amount + fee_platform_permanent_amount + fee_agent_permanent_amount
|
|
919
|
+
base_free_amount = free_amount - fee_platform_free_amount - fee_agent_free_amount
|
|
920
|
+
base_reward_amount = (
|
|
921
|
+
reward_amount - fee_platform_reward_amount - fee_agent_reward_amount
|
|
922
|
+
)
|
|
923
|
+
base_permanent_amount = (
|
|
924
|
+
permanent_amount - fee_platform_permanent_amount - fee_agent_permanent_amount
|
|
925
|
+
)
|
|
926
|
+
|
|
927
|
+
# 4. Update fee account - add credits with detailed amounts
|
|
928
|
+
message_account = await CreditAccount.income_in_session(
|
|
929
|
+
session=session,
|
|
930
|
+
owner_type=OwnerType.PLATFORM,
|
|
931
|
+
owner_id=DEFAULT_PLATFORM_ACCOUNT_MESSAGE,
|
|
932
|
+
amount_details={
|
|
933
|
+
CreditType.FREE: base_free_amount,
|
|
934
|
+
CreditType.REWARD: base_reward_amount,
|
|
935
|
+
CreditType.PERMANENT: base_permanent_amount,
|
|
936
|
+
},
|
|
937
|
+
event_id=event_id,
|
|
938
|
+
)
|
|
939
|
+
platform_fee_account = await CreditAccount.income_in_session(
|
|
940
|
+
session=session,
|
|
941
|
+
owner_type=OwnerType.PLATFORM,
|
|
942
|
+
owner_id=DEFAULT_PLATFORM_ACCOUNT_FEE,
|
|
943
|
+
amount_details={
|
|
944
|
+
CreditType.FREE: fee_platform_free_amount,
|
|
945
|
+
CreditType.REWARD: fee_platform_reward_amount,
|
|
946
|
+
CreditType.PERMANENT: fee_platform_permanent_amount,
|
|
947
|
+
},
|
|
948
|
+
event_id=event_id,
|
|
949
|
+
)
|
|
950
|
+
if fee_agent_amount > 0:
|
|
951
|
+
agent_account = await CreditAccount.income_in_session(
|
|
952
|
+
session=session,
|
|
953
|
+
owner_type=OwnerType.AGENT,
|
|
954
|
+
owner_id=agent.id,
|
|
955
|
+
amount_details={
|
|
956
|
+
CreditType.FREE: fee_agent_free_amount,
|
|
957
|
+
CreditType.REWARD: fee_agent_reward_amount,
|
|
958
|
+
CreditType.PERMANENT: fee_agent_permanent_amount,
|
|
959
|
+
},
|
|
960
|
+
event_id=event_id,
|
|
961
|
+
)
|
|
962
|
+
|
|
928
963
|
# Get agent wallet address
|
|
929
964
|
agent_data = await AgentData.get(agent.id)
|
|
930
965
|
agent_wallet_address = agent_data.evm_wallet_address if agent_data else None
|
|
@@ -977,6 +1012,9 @@ async def expense_message(
|
|
|
977
1012
|
credit_debit=CreditDebit.DEBIT,
|
|
978
1013
|
change_amount=total_amount,
|
|
979
1014
|
credit_type=credit_type,
|
|
1015
|
+
free_amount=free_amount,
|
|
1016
|
+
reward_amount=reward_amount,
|
|
1017
|
+
permanent_amount=permanent_amount,
|
|
980
1018
|
)
|
|
981
1019
|
session.add(user_tx)
|
|
982
1020
|
|
|
@@ -989,6 +1027,9 @@ async def expense_message(
|
|
|
989
1027
|
credit_debit=CreditDebit.CREDIT,
|
|
990
1028
|
change_amount=base_amount,
|
|
991
1029
|
credit_type=credit_type,
|
|
1030
|
+
free_amount=base_free_amount,
|
|
1031
|
+
reward_amount=base_reward_amount,
|
|
1032
|
+
permanent_amount=base_permanent_amount,
|
|
992
1033
|
)
|
|
993
1034
|
session.add(message_tx)
|
|
994
1035
|
|
|
@@ -1001,6 +1042,9 @@ async def expense_message(
|
|
|
1001
1042
|
credit_debit=CreditDebit.CREDIT,
|
|
1002
1043
|
change_amount=fee_platform_amount,
|
|
1003
1044
|
credit_type=credit_type,
|
|
1045
|
+
free_amount=fee_platform_free_amount,
|
|
1046
|
+
reward_amount=fee_platform_reward_amount,
|
|
1047
|
+
permanent_amount=fee_platform_permanent_amount,
|
|
1004
1048
|
)
|
|
1005
1049
|
session.add(platform_tx)
|
|
1006
1050
|
|
|
@@ -1014,6 +1058,9 @@ async def expense_message(
|
|
|
1014
1058
|
credit_debit=CreditDebit.CREDIT,
|
|
1015
1059
|
change_amount=fee_agent_amount,
|
|
1016
1060
|
credit_type=credit_type,
|
|
1061
|
+
free_amount=fee_agent_free_amount,
|
|
1062
|
+
reward_amount=fee_agent_reward_amount,
|
|
1063
|
+
permanent_amount=fee_agent_permanent_amount,
|
|
1017
1064
|
)
|
|
1018
1065
|
session.add(agent_tx)
|
|
1019
1066
|
|
|
@@ -1170,43 +1217,7 @@ async def expense_skill(
|
|
|
1170
1217
|
session=session, id=agent.id, amount=details[CreditType.FREE]
|
|
1171
1218
|
)
|
|
1172
1219
|
|
|
1173
|
-
# 3.
|
|
1174
|
-
skill_account = await CreditAccount.income_in_session(
|
|
1175
|
-
session=session,
|
|
1176
|
-
owner_type=OwnerType.PLATFORM,
|
|
1177
|
-
owner_id=DEFAULT_PLATFORM_ACCOUNT_SKILL,
|
|
1178
|
-
credit_type=CreditType.PERMANENT,
|
|
1179
|
-
amount=skill_cost_info.base_amount,
|
|
1180
|
-
event_id=event_id,
|
|
1181
|
-
)
|
|
1182
|
-
platform_account = await CreditAccount.income_in_session(
|
|
1183
|
-
session=session,
|
|
1184
|
-
owner_type=OwnerType.PLATFORM,
|
|
1185
|
-
owner_id=DEFAULT_PLATFORM_ACCOUNT_FEE,
|
|
1186
|
-
credit_type=CreditType.PERMANENT,
|
|
1187
|
-
amount=skill_cost_info.fee_platform_amount,
|
|
1188
|
-
event_id=event_id,
|
|
1189
|
-
)
|
|
1190
|
-
if skill_cost_info.fee_dev_amount > 0:
|
|
1191
|
-
dev_account = await CreditAccount.income_in_session(
|
|
1192
|
-
session=session,
|
|
1193
|
-
owner_type=skill_cost_info.fee_dev_user_type,
|
|
1194
|
-
owner_id=skill_cost_info.fee_dev_user,
|
|
1195
|
-
credit_type=CreditType.REWARD, # put dev fee in reward
|
|
1196
|
-
amount=skill_cost_info.fee_dev_amount,
|
|
1197
|
-
event_id=event_id,
|
|
1198
|
-
)
|
|
1199
|
-
if skill_cost_info.fee_agent_amount > 0:
|
|
1200
|
-
agent_account = await CreditAccount.income_in_session(
|
|
1201
|
-
session=session,
|
|
1202
|
-
owner_type=OwnerType.AGENT,
|
|
1203
|
-
owner_id=agent.id,
|
|
1204
|
-
credit_type=CreditType.REWARD,
|
|
1205
|
-
amount=skill_cost_info.fee_agent_amount,
|
|
1206
|
-
event_id=event_id,
|
|
1207
|
-
)
|
|
1208
|
-
|
|
1209
|
-
# 4. Create credit event record
|
|
1220
|
+
# 3. Calculate detailed amounts for fees
|
|
1210
1221
|
# Set the appropriate credit amount field based on credit type
|
|
1211
1222
|
free_amount = details.get(CreditType.FREE, Decimal("0"))
|
|
1212
1223
|
reward_amount = details.get(CreditType.REWARD, Decimal("0"))
|
|
@@ -1306,6 +1317,78 @@ async def expense_skill(
|
|
|
1306
1317
|
skill_cost_info.fee_dev_amount - fee_dev_free_amount - fee_dev_reward_amount
|
|
1307
1318
|
).quantize(FOURPLACES, rounding=ROUND_HALF_UP)
|
|
1308
1319
|
|
|
1320
|
+
# Calculate base amounts by credit type using subtraction method
|
|
1321
|
+
base_free_amount = (
|
|
1322
|
+
free_amount
|
|
1323
|
+
- fee_platform_free_amount
|
|
1324
|
+
- fee_agent_free_amount
|
|
1325
|
+
- fee_dev_free_amount
|
|
1326
|
+
)
|
|
1327
|
+
|
|
1328
|
+
base_reward_amount = (
|
|
1329
|
+
reward_amount
|
|
1330
|
+
- fee_platform_reward_amount
|
|
1331
|
+
- fee_agent_reward_amount
|
|
1332
|
+
- fee_dev_reward_amount
|
|
1333
|
+
)
|
|
1334
|
+
|
|
1335
|
+
base_permanent_amount = (
|
|
1336
|
+
permanent_amount
|
|
1337
|
+
- fee_platform_permanent_amount
|
|
1338
|
+
- fee_agent_permanent_amount
|
|
1339
|
+
- fee_dev_permanent_amount
|
|
1340
|
+
)
|
|
1341
|
+
|
|
1342
|
+
# 4. Update fee account - add credits
|
|
1343
|
+
skill_account = await CreditAccount.income_in_session(
|
|
1344
|
+
session=session,
|
|
1345
|
+
owner_type=OwnerType.PLATFORM,
|
|
1346
|
+
owner_id=DEFAULT_PLATFORM_ACCOUNT_SKILL,
|
|
1347
|
+
amount_details={
|
|
1348
|
+
CreditType.FREE: base_free_amount,
|
|
1349
|
+
CreditType.REWARD: base_reward_amount,
|
|
1350
|
+
CreditType.PERMANENT: base_permanent_amount,
|
|
1351
|
+
},
|
|
1352
|
+
event_id=event_id,
|
|
1353
|
+
)
|
|
1354
|
+
platform_account = await CreditAccount.income_in_session(
|
|
1355
|
+
session=session,
|
|
1356
|
+
owner_type=OwnerType.PLATFORM,
|
|
1357
|
+
owner_id=DEFAULT_PLATFORM_ACCOUNT_FEE,
|
|
1358
|
+
amount_details={
|
|
1359
|
+
CreditType.FREE: fee_platform_free_amount,
|
|
1360
|
+
CreditType.REWARD: fee_platform_reward_amount,
|
|
1361
|
+
CreditType.PERMANENT: fee_platform_permanent_amount,
|
|
1362
|
+
},
|
|
1363
|
+
event_id=event_id,
|
|
1364
|
+
)
|
|
1365
|
+
if skill_cost_info.fee_dev_amount > 0:
|
|
1366
|
+
dev_account = await CreditAccount.income_in_session(
|
|
1367
|
+
session=session,
|
|
1368
|
+
owner_type=skill_cost_info.fee_dev_user_type,
|
|
1369
|
+
owner_id=skill_cost_info.fee_dev_user,
|
|
1370
|
+
amount_details={
|
|
1371
|
+
CreditType.FREE: fee_dev_free_amount,
|
|
1372
|
+
CreditType.REWARD: fee_dev_reward_amount,
|
|
1373
|
+
CreditType.PERMANENT: fee_dev_permanent_amount,
|
|
1374
|
+
},
|
|
1375
|
+
event_id=event_id,
|
|
1376
|
+
)
|
|
1377
|
+
if skill_cost_info.fee_agent_amount > 0:
|
|
1378
|
+
agent_account = await CreditAccount.income_in_session(
|
|
1379
|
+
session=session,
|
|
1380
|
+
owner_type=OwnerType.AGENT,
|
|
1381
|
+
owner_id=agent.id,
|
|
1382
|
+
amount_details={
|
|
1383
|
+
CreditType.FREE: fee_agent_free_amount,
|
|
1384
|
+
CreditType.REWARD: fee_agent_reward_amount,
|
|
1385
|
+
CreditType.PERMANENT: fee_agent_permanent_amount,
|
|
1386
|
+
},
|
|
1387
|
+
event_id=event_id,
|
|
1388
|
+
)
|
|
1389
|
+
|
|
1390
|
+
# 5. Create credit event record
|
|
1391
|
+
|
|
1309
1392
|
# Get agent wallet address
|
|
1310
1393
|
agent_data = await AgentData.get(agent.id)
|
|
1311
1394
|
agent_wallet_address = agent_data.evm_wallet_address if agent_data else None
|
|
@@ -1366,6 +1449,9 @@ async def expense_skill(
|
|
|
1366
1449
|
credit_debit=CreditDebit.DEBIT,
|
|
1367
1450
|
change_amount=skill_cost_info.total_amount,
|
|
1368
1451
|
credit_type=credit_type,
|
|
1452
|
+
free_amount=free_amount,
|
|
1453
|
+
reward_amount=reward_amount,
|
|
1454
|
+
permanent_amount=permanent_amount,
|
|
1369
1455
|
)
|
|
1370
1456
|
session.add(user_tx)
|
|
1371
1457
|
|
|
@@ -1378,6 +1464,9 @@ async def expense_skill(
|
|
|
1378
1464
|
credit_debit=CreditDebit.CREDIT,
|
|
1379
1465
|
change_amount=skill_cost_info.base_amount,
|
|
1380
1466
|
credit_type=credit_type,
|
|
1467
|
+
free_amount=base_free_amount,
|
|
1468
|
+
reward_amount=base_reward_amount,
|
|
1469
|
+
permanent_amount=base_permanent_amount,
|
|
1381
1470
|
)
|
|
1382
1471
|
session.add(skill_tx)
|
|
1383
1472
|
|
|
@@ -1390,6 +1479,9 @@ async def expense_skill(
|
|
|
1390
1479
|
credit_debit=CreditDebit.CREDIT,
|
|
1391
1480
|
change_amount=skill_cost_info.fee_platform_amount,
|
|
1392
1481
|
credit_type=credit_type,
|
|
1482
|
+
free_amount=fee_platform_free_amount,
|
|
1483
|
+
reward_amount=fee_platform_reward_amount,
|
|
1484
|
+
permanent_amount=fee_platform_permanent_amount,
|
|
1393
1485
|
)
|
|
1394
1486
|
session.add(platform_tx)
|
|
1395
1487
|
|
|
@@ -1403,6 +1495,9 @@ async def expense_skill(
|
|
|
1403
1495
|
credit_debit=CreditDebit.CREDIT,
|
|
1404
1496
|
change_amount=skill_cost_info.fee_dev_amount,
|
|
1405
1497
|
credit_type=CreditType.REWARD,
|
|
1498
|
+
free_amount=fee_dev_free_amount,
|
|
1499
|
+
reward_amount=fee_dev_reward_amount,
|
|
1500
|
+
permanent_amount=fee_dev_permanent_amount,
|
|
1406
1501
|
)
|
|
1407
1502
|
session.add(dev_tx)
|
|
1408
1503
|
|
|
@@ -1416,6 +1511,9 @@ async def expense_skill(
|
|
|
1416
1511
|
credit_debit=CreditDebit.CREDIT,
|
|
1417
1512
|
change_amount=skill_cost_info.fee_agent_amount,
|
|
1418
1513
|
credit_type=credit_type,
|
|
1514
|
+
free_amount=fee_agent_free_amount,
|
|
1515
|
+
reward_amount=fee_agent_reward_amount,
|
|
1516
|
+
permanent_amount=fee_agent_permanent_amount,
|
|
1419
1517
|
)
|
|
1420
1518
|
session.add(agent_tx)
|
|
1421
1519
|
|
|
@@ -1460,8 +1558,7 @@ async def refill_free_credits_for_account(
|
|
|
1460
1558
|
session=session,
|
|
1461
1559
|
owner_type=account.owner_type,
|
|
1462
1560
|
owner_id=account.owner_id,
|
|
1463
|
-
|
|
1464
|
-
credit_type=CreditType.FREE,
|
|
1561
|
+
amount_details={CreditType.FREE: amount_to_add},
|
|
1465
1562
|
event_id=event_id,
|
|
1466
1563
|
)
|
|
1467
1564
|
|
|
@@ -1636,38 +1733,12 @@ async def expense_summarize(
|
|
|
1636
1733
|
session=session, id=agent.id, amount=details.get(CreditType.FREE)
|
|
1637
1734
|
)
|
|
1638
1735
|
|
|
1639
|
-
# 3.
|
|
1640
|
-
memory_account = await CreditAccount.income_in_session(
|
|
1641
|
-
session=session,
|
|
1642
|
-
owner_type=OwnerType.PLATFORM,
|
|
1643
|
-
owner_id=DEFAULT_PLATFORM_ACCOUNT_MEMORY,
|
|
1644
|
-
credit_type=CreditType.PERMANENT,
|
|
1645
|
-
amount=base_amount,
|
|
1646
|
-
event_id=event_id,
|
|
1647
|
-
)
|
|
1648
|
-
platform_fee_account = await CreditAccount.income_in_session(
|
|
1649
|
-
session=session,
|
|
1650
|
-
owner_type=OwnerType.PLATFORM,
|
|
1651
|
-
owner_id=DEFAULT_PLATFORM_ACCOUNT_FEE,
|
|
1652
|
-
credit_type=CreditType.PERMANENT,
|
|
1653
|
-
amount=fee_platform_amount,
|
|
1654
|
-
event_id=event_id,
|
|
1655
|
-
)
|
|
1656
|
-
if fee_agent_amount > 0:
|
|
1657
|
-
agent_account = await CreditAccount.income_in_session(
|
|
1658
|
-
session=session,
|
|
1659
|
-
owner_type=OwnerType.AGENT,
|
|
1660
|
-
owner_id=agent.id,
|
|
1661
|
-
credit_type=CreditType.REWARD,
|
|
1662
|
-
amount=fee_agent_amount,
|
|
1663
|
-
event_id=event_id,
|
|
1664
|
-
)
|
|
1665
|
-
|
|
1666
|
-
# 4. Create credit event record
|
|
1736
|
+
# 3. Calculate fee amounts by credit type before income_in_session calls
|
|
1667
1737
|
# Set the appropriate credit amount field based on credit type
|
|
1668
1738
|
free_amount = details.get(CreditType.FREE, Decimal("0"))
|
|
1669
1739
|
reward_amount = details.get(CreditType.REWARD, Decimal("0"))
|
|
1670
1740
|
permanent_amount = details.get(CreditType.PERMANENT, Decimal("0"))
|
|
1741
|
+
|
|
1671
1742
|
if CreditType.PERMANENT in details:
|
|
1672
1743
|
credit_type = CreditType.PERMANENT
|
|
1673
1744
|
elif CreditType.REWARD in details:
|
|
@@ -1719,6 +1790,55 @@ async def expense_summarize(
|
|
|
1719
1790
|
fee_agent_amount - fee_agent_free_amount - fee_agent_reward_amount
|
|
1720
1791
|
).quantize(FOURPLACES, rounding=ROUND_HALF_UP)
|
|
1721
1792
|
|
|
1793
|
+
# Calculate base amounts by credit type using subtraction method
|
|
1794
|
+
base_free_amount = free_amount - fee_platform_free_amount - fee_agent_free_amount
|
|
1795
|
+
|
|
1796
|
+
base_reward_amount = (
|
|
1797
|
+
reward_amount - fee_platform_reward_amount - fee_agent_reward_amount
|
|
1798
|
+
)
|
|
1799
|
+
|
|
1800
|
+
base_permanent_amount = (
|
|
1801
|
+
permanent_amount - fee_platform_permanent_amount - fee_agent_permanent_amount
|
|
1802
|
+
)
|
|
1803
|
+
|
|
1804
|
+
# 4. Update fee account - add credits
|
|
1805
|
+
memory_account = await CreditAccount.income_in_session(
|
|
1806
|
+
session=session,
|
|
1807
|
+
owner_type=OwnerType.PLATFORM,
|
|
1808
|
+
owner_id=DEFAULT_PLATFORM_ACCOUNT_MEMORY,
|
|
1809
|
+
amount_details={
|
|
1810
|
+
CreditType.FREE: base_free_amount,
|
|
1811
|
+
CreditType.REWARD: base_reward_amount,
|
|
1812
|
+
CreditType.PERMANENT: base_permanent_amount,
|
|
1813
|
+
},
|
|
1814
|
+
event_id=event_id,
|
|
1815
|
+
)
|
|
1816
|
+
platform_fee_account = await CreditAccount.income_in_session(
|
|
1817
|
+
session=session,
|
|
1818
|
+
owner_type=OwnerType.PLATFORM,
|
|
1819
|
+
owner_id=DEFAULT_PLATFORM_ACCOUNT_FEE,
|
|
1820
|
+
amount_details={
|
|
1821
|
+
CreditType.FREE: fee_platform_free_amount,
|
|
1822
|
+
CreditType.REWARD: fee_platform_reward_amount,
|
|
1823
|
+
CreditType.PERMANENT: fee_platform_permanent_amount,
|
|
1824
|
+
},
|
|
1825
|
+
event_id=event_id,
|
|
1826
|
+
)
|
|
1827
|
+
if fee_agent_amount > 0:
|
|
1828
|
+
agent_account = await CreditAccount.income_in_session(
|
|
1829
|
+
session=session,
|
|
1830
|
+
owner_type=OwnerType.AGENT,
|
|
1831
|
+
owner_id=agent.id,
|
|
1832
|
+
amount_details={
|
|
1833
|
+
CreditType.FREE: fee_agent_free_amount,
|
|
1834
|
+
CreditType.REWARD: fee_agent_reward_amount,
|
|
1835
|
+
CreditType.PERMANENT: fee_agent_permanent_amount,
|
|
1836
|
+
},
|
|
1837
|
+
event_id=event_id,
|
|
1838
|
+
)
|
|
1839
|
+
|
|
1840
|
+
# 5. Create credit event record
|
|
1841
|
+
|
|
1722
1842
|
# Get agent wallet address
|
|
1723
1843
|
agent_data = await AgentData.get(agent.id)
|
|
1724
1844
|
agent_wallet_address = agent_data.evm_wallet_address if agent_data else None
|
|
@@ -1769,6 +1889,9 @@ async def expense_summarize(
|
|
|
1769
1889
|
credit_debit=CreditDebit.DEBIT,
|
|
1770
1890
|
change_amount=total_amount,
|
|
1771
1891
|
credit_type=credit_type,
|
|
1892
|
+
free_amount=free_amount,
|
|
1893
|
+
reward_amount=reward_amount,
|
|
1894
|
+
permanent_amount=permanent_amount,
|
|
1772
1895
|
)
|
|
1773
1896
|
session.add(user_tx)
|
|
1774
1897
|
|
|
@@ -1781,6 +1904,9 @@ async def expense_summarize(
|
|
|
1781
1904
|
credit_debit=CreditDebit.CREDIT,
|
|
1782
1905
|
change_amount=base_amount,
|
|
1783
1906
|
credit_type=credit_type,
|
|
1907
|
+
free_amount=base_free_amount,
|
|
1908
|
+
reward_amount=base_reward_amount,
|
|
1909
|
+
permanent_amount=base_permanent_amount,
|
|
1784
1910
|
)
|
|
1785
1911
|
session.add(memory_tx)
|
|
1786
1912
|
|
|
@@ -1793,6 +1919,9 @@ async def expense_summarize(
|
|
|
1793
1919
|
credit_debit=CreditDebit.CREDIT,
|
|
1794
1920
|
change_amount=fee_platform_amount,
|
|
1795
1921
|
credit_type=credit_type,
|
|
1922
|
+
free_amount=fee_platform_free_amount,
|
|
1923
|
+
reward_amount=fee_platform_reward_amount,
|
|
1924
|
+
permanent_amount=fee_platform_permanent_amount,
|
|
1796
1925
|
)
|
|
1797
1926
|
session.add(platform_tx)
|
|
1798
1927
|
|
|
@@ -1806,6 +1935,9 @@ async def expense_summarize(
|
|
|
1806
1935
|
credit_debit=CreditDebit.CREDIT,
|
|
1807
1936
|
change_amount=fee_agent_amount,
|
|
1808
1937
|
credit_type=CreditType.REWARD,
|
|
1938
|
+
free_amount=fee_agent_free_amount,
|
|
1939
|
+
reward_amount=fee_agent_reward_amount,
|
|
1940
|
+
permanent_amount=fee_agent_permanent_amount,
|
|
1809
1941
|
)
|
|
1810
1942
|
session.add(agent_tx)
|
|
1811
1943
|
|
intentkit/models/credit.py
CHANGED
|
@@ -404,20 +404,25 @@ class CreditAccount(BaseModel):
|
|
|
404
404
|
session: AsyncSession,
|
|
405
405
|
owner_type: OwnerType,
|
|
406
406
|
owner_id: str,
|
|
407
|
-
|
|
408
|
-
credit_type: CreditType,
|
|
407
|
+
amount_details: Dict[CreditType, Decimal],
|
|
409
408
|
event_id: Optional[str] = None,
|
|
410
409
|
) -> "CreditAccount":
|
|
411
410
|
# check first, create if not exists
|
|
412
411
|
await cls.get_or_create_in_session(session, owner_type, owner_id)
|
|
413
412
|
# income
|
|
414
413
|
values_dict = {
|
|
415
|
-
credit_type.value: getattr(CreditAccountTable, credit_type.value) + amount,
|
|
416
414
|
"income_at": datetime.now(timezone.utc),
|
|
417
415
|
}
|
|
418
416
|
if event_id:
|
|
419
417
|
values_dict["last_event_id"] = event_id
|
|
420
418
|
|
|
419
|
+
# Add credit type values based on amount_details
|
|
420
|
+
for credit_type, amount in amount_details.items():
|
|
421
|
+
if amount > 0:
|
|
422
|
+
values_dict[credit_type.value] = (
|
|
423
|
+
getattr(CreditAccountTable, credit_type.value) + amount
|
|
424
|
+
)
|
|
425
|
+
|
|
421
426
|
stmt = (
|
|
422
427
|
update(CreditAccountTable)
|
|
423
428
|
.where(
|
|
@@ -534,6 +539,9 @@ class CreditAccount(BaseModel):
|
|
|
534
539
|
credit_debit=CreditDebit.CREDIT,
|
|
535
540
|
change_amount=free_quota,
|
|
536
541
|
credit_type=CreditType.FREE,
|
|
542
|
+
free_amount=free_quota,
|
|
543
|
+
reward_amount=Decimal("0"),
|
|
544
|
+
permanent_amount=Decimal("0"),
|
|
537
545
|
)
|
|
538
546
|
session.add(user_tx)
|
|
539
547
|
|
|
@@ -546,6 +554,9 @@ class CreditAccount(BaseModel):
|
|
|
546
554
|
credit_debit=CreditDebit.DEBIT,
|
|
547
555
|
change_amount=free_quota,
|
|
548
556
|
credit_type=CreditType.FREE,
|
|
557
|
+
free_amount=free_quota,
|
|
558
|
+
reward_amount=Decimal("0"),
|
|
559
|
+
permanent_amount=Decimal("0"),
|
|
549
560
|
)
|
|
550
561
|
session.add(platform_tx)
|
|
551
562
|
|
|
@@ -1183,6 +1194,21 @@ class CreditTransactionTable(Base):
|
|
|
1183
1194
|
default=0,
|
|
1184
1195
|
nullable=False,
|
|
1185
1196
|
)
|
|
1197
|
+
free_amount = Column(
|
|
1198
|
+
Numeric(22, 4),
|
|
1199
|
+
default=0,
|
|
1200
|
+
nullable=False,
|
|
1201
|
+
)
|
|
1202
|
+
reward_amount = Column(
|
|
1203
|
+
Numeric(22, 4),
|
|
1204
|
+
default=0,
|
|
1205
|
+
nullable=False,
|
|
1206
|
+
)
|
|
1207
|
+
permanent_amount = Column(
|
|
1208
|
+
Numeric(22, 4),
|
|
1209
|
+
default=0,
|
|
1210
|
+
nullable=False,
|
|
1211
|
+
)
|
|
1186
1212
|
credit_type = Column(
|
|
1187
1213
|
String,
|
|
1188
1214
|
nullable=False,
|
|
@@ -1223,8 +1249,22 @@ class CreditTransaction(BaseModel):
|
|
|
1223
1249
|
change_amount: Annotated[
|
|
1224
1250
|
Decimal, Field(default=Decimal("0"), description="Amount of credits changed")
|
|
1225
1251
|
]
|
|
1252
|
+
free_amount: Annotated[
|
|
1253
|
+
Decimal,
|
|
1254
|
+
Field(default=Decimal("0"), description="Amount of free credits changed"),
|
|
1255
|
+
]
|
|
1256
|
+
reward_amount: Annotated[
|
|
1257
|
+
Decimal,
|
|
1258
|
+
Field(default=Decimal("0"), description="Amount of reward credits changed"),
|
|
1259
|
+
]
|
|
1260
|
+
permanent_amount: Annotated[
|
|
1261
|
+
Decimal,
|
|
1262
|
+
Field(default=Decimal("0"), description="Amount of permanent credits changed"),
|
|
1263
|
+
]
|
|
1226
1264
|
|
|
1227
|
-
@field_validator(
|
|
1265
|
+
@field_validator(
|
|
1266
|
+
"change_amount", "free_amount", "reward_amount", "permanent_amount"
|
|
1267
|
+
)
|
|
1228
1268
|
@classmethod
|
|
1229
1269
|
def round_decimal(cls, v: Any) -> Decimal:
|
|
1230
1270
|
"""Round decimal values to 4 decimal places."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: intentkit
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.19.dev1
|
|
4
4
|
Summary: Intent-based AI Agent Platform - Core Package
|
|
5
5
|
Project-URL: Homepage, https://github.com/crestal-network/intentkit
|
|
6
6
|
Project-URL: Repository, https://github.com/crestal-network/intentkit
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
intentkit/__init__.py,sha256=
|
|
1
|
+
intentkit/__init__.py,sha256=quyhcKChclMLhjuy8LzOR07Mg7jKRnXvuDEATLIHjyU,384
|
|
2
2
|
intentkit/abstracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
intentkit/abstracts/agent.py,sha256=108gb5W8Q1Sy4G55F2_ZFv2-_CnY76qrBtpIr0Oxxqk,1489
|
|
4
4
|
intentkit/abstracts/api.py,sha256=ZUc24vaQvQVbbjznx7bV0lbbQxdQPfEV8ZxM2R6wZWo,166
|
|
@@ -15,7 +15,7 @@ intentkit/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
15
15
|
intentkit/core/agent.py,sha256=GIKDn1dTenIHWMRxe-ud7hd1cQaHzbTDdypy5IAgPfU,16658
|
|
16
16
|
intentkit/core/api.py,sha256=WfoaHNquujYJIpNPuTR1dSaaxog0S3X2W4lG9Ehmkm4,3284
|
|
17
17
|
intentkit/core/client.py,sha256=J5K7f08-ucszBKAbn9K3QNOFKIC__7amTbKYii1jFkI,3056
|
|
18
|
-
intentkit/core/credit.py,sha256=
|
|
18
|
+
intentkit/core/credit.py,sha256=kA9h8BcsEOZ57AEvK9idlQqD0vej_EWgeOc-c_DRevw,68341
|
|
19
19
|
intentkit/core/engine.py,sha256=H4ew1jhn2coMYJ3zR9isM1Y-XbnXNMg91SeDoeXdQ4U,36562
|
|
20
20
|
intentkit/core/node.py,sha256=7h9zgDSd928bzUi3m3EZnKkhbwqlbRAQUr_uz7gKB5Y,8880
|
|
21
21
|
intentkit/core/prompt.py,sha256=a6nogIGZuDt2u2EuDd29DAv73OjCBOn-bZnuqYRvY7A,15804
|
|
@@ -27,7 +27,7 @@ intentkit/models/app_setting.py,sha256=iYbW63QD91bt4oEYV3wOXHuRFav2b4VXLwb_StgUQ
|
|
|
27
27
|
intentkit/models/base.py,sha256=o-zRjVrak-f5Jokdvj8BjLm8gcC3yYiYMCTLegwT2lA,185
|
|
28
28
|
intentkit/models/chat.py,sha256=4z5y0Q77XsVABeGMRXnxlY2Ol6gnivTxeMrlO04IB-Q,20494
|
|
29
29
|
intentkit/models/conversation.py,sha256=nrbDIw-3GK5BYi_xkI15FLdx4a6SNrFK8wfAGLCsrqk,9032
|
|
30
|
-
intentkit/models/credit.py,sha256=
|
|
30
|
+
intentkit/models/credit.py,sha256=o5jJGX1Hn8vWhkMRzo3eV8aIFEHBFkKtlLl0x5_8rLo,44198
|
|
31
31
|
intentkit/models/db.py,sha256=nuDX6NEtnfD5YLr2iVpAAXsgHbSpG5diqfLC-PkHsA4,4406
|
|
32
32
|
intentkit/models/db_mig.py,sha256=vT6Tanm-BHC2T7dTztuB1UG494EFBAlHADKsNzR6xaQ,3577
|
|
33
33
|
intentkit/models/generator.py,sha256=lyZu9U9rZUGkqd_QT5SAhay9DY358JJY8EhDSpN8I1M,10298
|
|
@@ -411,7 +411,7 @@ intentkit/utils/random.py,sha256=DymMxu9g0kuQLgJUqalvgksnIeLdS-v0aRk5nQU0mLI,452
|
|
|
411
411
|
intentkit/utils/s3.py,sha256=9trQNkKQ5VgxWsewVsV8Y0q_pXzGRvsCYP8xauyUYkg,8549
|
|
412
412
|
intentkit/utils/slack_alert.py,sha256=s7UpRgyzLW7Pbmt8cKzTJgMA9bm4EP-1rQ5KXayHu6E,2264
|
|
413
413
|
intentkit/utils/tx.py,sha256=2yLLGuhvfBEY5n_GJ8wmIWLCzn0FsYKv5kRNzw_sLUI,1454
|
|
414
|
-
intentkit-0.6.
|
|
415
|
-
intentkit-0.6.
|
|
416
|
-
intentkit-0.6.
|
|
417
|
-
intentkit-0.6.
|
|
414
|
+
intentkit-0.6.19.dev1.dist-info/METADATA,sha256=BgyilNciFNBjtrR1TbV2aLHYv66HE9owOSnAYWk_dlo,6414
|
|
415
|
+
intentkit-0.6.19.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
416
|
+
intentkit-0.6.19.dev1.dist-info/licenses/LICENSE,sha256=Bln6DhK-LtcO4aXy-PBcdZv2f24MlJFm_qn222biJtE,1071
|
|
417
|
+
intentkit-0.6.19.dev1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|